将帖子或页面移动到废纸篓
原型
wp_trash_post( int $post_id )
描述
如果禁用垃圾箱,则会永久删除帖子或页面。
参考:
- wp_delete_post()
参数
$post_id
(int)
(Optional)
帖子ID。如果EMPTY_TRASH_DAYS等于true,则默认为全局$ post的ID。
返回值
(WP_Post|false|null)
发布成功数据,错误或失败时返回null。
源文件
路径:wp-includes/post.php
<?php
...
function wp_trash_post( $post_id = 0 ) {
if ( ! EMPTY_TRASH_DAYS ) {
return wp_delete_post( $post_id, true );
}
$post = get_post( $post_id );
if ( ! $post ) {
return $post;
}
if ( 'trash' === $post->post_status ) {
return false;
}
/**
* Filters whether a post trashing should take place.
*
* @since 4.9.0
*
* @param bool $trash Whether to go forward with trashing.
* @param WP_Post $post Post object.
*/
$check = apply_filters( 'pre_trash_post', null, $post );
if ( null !== $check ) {
return $check;
}
/**
* Fires before a post is sent to the trash.
*
* @since 3.3.0
*
* @param int $post_id Post ID.
*/
do_action( 'wp_trash_post', $post_id );
add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
add_post_meta( $post_id, '_wp_trash_meta_time', time() );
wp_update_post( array( 'ID' => $post_id, 'post_status' => 'trash' ) );
wp_trash_post_comments( $post_id );
/**
* Fires after a post is sent to the trash.
*
* @since 2.9.0
*
* @param int $post_id Post ID.
*/
do_action( 'trashed_post', $post_id );
return $post;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_trash_post/