wp_untrash_post
函数
wp_untrash_post ( $post_id = 0 )
- 参数
-
-
(int)
$post_id
Optional. Post ID. Default is the ID of the global `$post`.- Required: 否
-
(int)
- 返回值
-
- (WP_Post|false|null) Post data on success, false or null on failure.
- 定义位置
-
-
wp-includes/post.php
, line 3624
-
wp-includes/post.php
- 引入
- 2.9.0
- 弃用
- –
Restores a post from the Trash.
function wp_untrash_post( $post_id = 0 ) { $post = get_post( $post_id ); if ( ! $post ) { return $post; } $post_id = $post->ID; if ( 'trash' !== $post->post_status ) { return false; } $previous_status = get_post_meta( $post_id, '_wp_trash_meta_status', true ); /** * Filters whether a post untrashing should take place. * * @since 4.9.0 * @since 5.6.0 The `$previous_status` parameter was added. * * @param bool|null $untrash Whether to go forward with untrashing. * @param WP_Post $post Post object. * @param string $previous_status The status of the post at the point where it was trashed. */ $check = apply_filters( 'pre_untrash_post', null, $post, $previous_status ); if ( null !== $check ) { return $check; } /** * Fires before a post is restored from the Trash. * * @since 2.9.0 * @since 5.6.0 The `$previous_status` parameter was added. * * @param int $post_id Post ID. * @param string $previous_status The status of the post at the point where it was trashed. */ do_action( 'untrash_post', $post_id, $previous_status ); $new_status = ( 'attachment' === $post->post_type ) ? 'inherit' : 'draft'; /** * Filters the status that a post gets assigned when it is restored from the trash (untrashed). * * By default posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status` * in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()` * function is available for this. * * Prior to WordPress 5.6.0, restored posts were always assigned their original status. * * @since 5.6.0 * * @param string $new_status The new status of the post being restored. * @param int $post_id The ID of the post being restored. * @param string $previous_status The status of the post at the point where it was trashed. */ $post_status = apply_filters( 'wp_untrash_post_status', $new_status, $post_id, $previous_status ); delete_post_meta( $post_id, '_wp_trash_meta_status' ); delete_post_meta( $post_id, '_wp_trash_meta_time' ); $post_updated = wp_update_post( array( 'ID' => $post_id, 'post_status' => $post_status, ) ); if ( ! $post_updated ) { return false; } wp_untrash_post_comments( $post_id ); /** * Fires after a post is restored from the Trash. * * @since 2.9.0 * @since 5.6.0 The `$previous_status` parameter was added. * * @param int $post_id Post ID. * @param string $previous_status The status of the post at the point where it was trashed. */ do_action( 'untrashed_post', $post_id, $previous_status ); return $post; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。