WordPress函数wp_trash_post()通过id删除一篇文章到回收站

描述:

通过id删除一篇文章到回收站

用法:

<?php wp_trash_post( $post_id  ); ?>

参数:

$post_id

(integer) (可选) 文章ID

默认值: 0

源文件:

/**
 * 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;
}