WP_Customize_Manager::trash_changeset_post( int|WP_Post $post ): mixed

Trashes or deletes a changeset post.

Description

The following re-formulates the logic from wp_trash_post() as done in wp_publish_post(). The reason for bypassing wp_trash_post() is that it will mutate the the post_content and the post_name when they should be untouched.

See also

Parameters

$postint|WP_Postrequired
The changeset post.

Return

mixed A WP_Post object for the trashed post or an empty value on failure.

Source

public function trash_changeset_post( $post ) {
	global $wpdb;

	$post = get_post( $post );

	if ( ! ( $post instanceof WP_Post ) ) {
		return $post;
	}
	$post_id = $post->ID;

	if ( ! EMPTY_TRASH_DAYS ) {
		return wp_delete_post( $post_id, true );
	}

	if ( 'trash' === get_post_status( $post ) ) {
		return false;
	}

	/** This filter is documented in wp-includes/post.php */
	$check = apply_filters( 'pre_trash_post', null, $post );
	if ( null !== $check ) {
		return $check;
	}

	/** This action is documented in wp-includes/post.php */
	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() );

	$old_status = $post->post_status;
	$new_status = 'trash';
	$wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) );
	clean_post_cache( $post->ID );

	$post->post_status = $new_status;
	wp_transition_post_status( $new_status, $old_status, $post );

	/** This action is documented in wp-includes/post.php */
	do_action( "edit_post_{$post->post_type}", $post->ID, $post );

	/** This action is documented in wp-includes/post.php */
	do_action( 'edit_post', $post->ID, $post );

	/** This action is documented in wp-includes/post.php */
	do_action( "save_post_{$post->post_type}", $post->ID, $post, true );

	/** This action is documented in wp-includes/post.php */
	do_action( 'save_post', $post->ID, $post, true );

	/** This action is documented in wp-includes/post.php */
	do_action( 'wp_insert_post', $post->ID, $post, true );

	wp_after_insert_post( get_post( $post_id ), true, $post );

	wp_trash_post_comments( $post_id );

	/** This action is documented in wp-includes/post.php */
	do_action( 'trashed_post', $post_id );

	return $post;
}

Hooks

do_action( ‘edit_post’, int $post_id, WP_Post $post )

Fires once an existing post has been updated.

do_action( “edit_post_{$post->post_type}”, int $post_id, WP_Post $post )

Fires once an existing post has been updated.

apply_filters( ‘pre_trash_post’, bool|null $trash, WP_Post $post, string $previous_status )

Filters whether a post trashing should take place.

do_action( ‘save_post’, int $post_id, WP_Post $post, bool $update )

Fires once a post has been saved.

do_action( “save_post_{$post->post_type}”, int $post_id, WP_Post $post, bool $update )

Fires once a post has been saved.

do_action( ‘trashed_post’, int $post_id, string $previous_status )

Fires after a post is sent to the Trash.

do_action( ‘wp_insert_post’, int $post_id, WP_Post $post, bool $update )

Fires once a post has been saved.

do_action( ‘wp_trash_post’, int $post_id, string $previous_status )

Fires before a post is sent to the Trash.

Changelog

VersionDescription
4.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.