wp_trash_post()
wp_trash_post( int $post_id ) 将文章或页面移到垃圾箱 Move a post o…
wp_trash_post( int $post_id )
将文章或页面移到垃圾箱
Move a post or page to the Trash
将文章或页面移到垃圾箱
Move a post or page to the Trash
目录锚点:#说明#参数#源码#笔记
说明(Description)
如果垃圾箱被禁用,文章或页面将被永久删除。另请参阅wp_delete_post()
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $post_id | (int) | Post ID。如果EMPTY_TRASH_DAYS等于true,则默认为全局$Post的ID。 |
源码(Source)
/**
* Move a post or page to the Trash
*
* If trash is disabled, the post or page is permanently deleted.
*
* @since 2.9.0
*
* @see wp_delete_post()
*
* @param int $post_id Optional. Post ID. Default is ID of the global $post
* if EMPTY_TRASH_DAYS equals true.
* @return false|array|WP_Post|null Post data array, otherwise false.
*/
function wp_trash_post( $post_id = 0 ) {
if ( !EMPTY_TRASH_DAYS )
return wp_delete_post($post_id, true);
if ( !$post = get_post($post_id, ARRAY_A) )
return $post;
if ( $post['post_status'] == 'trash' )
return false;
/**
* 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());
$post['post_status'] = 'trash';
wp_insert_post($post);
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;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.9.0 | wp-includes/post.php | 2 | 1 |
笔记(Notes)
基本示例
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!