返回介绍

wp_trash_post()

发布于 2017-09-11 13:00:41 字数 3151 浏览 1012 评论 0 收藏 0

wp_trash_post( int $post_id )

Move a post or page to the Trash


description

If trash is disabled, the post or page is permanently deleted.


参数

$post_id

(int) (Optional) Post ID. Default is ID of the global $post if EMPTY_TRASH_DAYS equals true.


返回值

(false|array|WP_Post|null) Post data array, otherwise false.


源代码

File: wp-includes/post.php

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( wp_slash( $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;
}

更新日志

Versiondescription
2.9.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: wp_slash()
  • wp-includes/plugin.php: do_action()
  • wp-includes/post.php: wp_insert_post()
  • wp-includes/post.php: wp_delete_post()
  • wp-includes/post.php: wp_trash_post_comments()
  • wp-includes/post.php: wp_trash_post
  • wp-includes/post.php: trashed_post
  • wp-includes/post.php: add_post_meta()
  • wp-includes/post.php: get_post()
  • Show 4 more uses Hide more uses

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::delete_item()
  • wp-admin/includes/ajax-actions.php: wp_ajax_trash_post()
  • wp-includes/post.php: wp_delete_attachment()
  • wp-includes/post.php: wp_delete_post()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    Trash the default WordPress Post, “Hello World,” which has an ID of ‘1’.

    
    <?php wp_trash_post( $post_id = 1 ); ?>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文