wp_trash_post

Definition:
function wp_trash_post($post_id = 0) {}

Moves a post or page to the Trash
If trash is disabled, the post or page is permanently deleted.

Parameters

  • int $post_id: Post ID.

Return values

returns:False on failure

Defined actions

  • wp_trash_post
    do_action('wp_trash_post', $post_id);
  • trashed_post
    do_action('trashed_post', $post_id);

Source code

function wp_trash_post($post_id = 0) {

	if ( !EMPTY_TRASH_DAYS )

		return wp_delete_post($post_id, true);



	if ( !$post = wp_get_single_post($post_id, ARRAY_A) )

		return $post;



	if ( $post['post_status'] == 'trash' )

		return false;



	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);



	do_action('trashed_post', $post_id);



	return $post;

}

4185

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: