wppaste
WordPress

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

Since
4.9.0
Source
wp-includes/class-wp-customize-manager.php:3072
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 post_content and the post_name when they should be untouched.

Compatibility

WordPress
since 4.9.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$postint|WP_Post
The changeset post.

Return value

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

Performance profile

How much work a call to WP_Customize_Manager::trash_changeset_post() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9–124

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 132.

Plugin surface
8 hooks

Third-party callbacks on 'pre_trash_post', 'wp_trash_post', 'edit_post_{$post->post_type}' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_delete()one call below WP_Customize_Manager::trash_changeset_post()

Further down the call graph this can also reach serialize, transient and option. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 5 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Manager::trash_changeset_post() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!($post instanceof)9get_post()
$post instanceof16get_post(), wp_delete_post()
$post instanceof17get_post(), get_post_status()
$post instanceof && $check !== null27get_post(), get_post_status(), apply_filters()
$post instanceof && $check === null124get_post(), get_post_status(), apply_filters(), do_action(), add_post_meta(), time(), add_post_meta(), ID(), clean_post_cache(), wp_transition_post_status(), do_action(), do_action(), do_action(), do_action(), do_action(), get_post(), wp_after_insert_post(), wp_trash_post_comments(), do_action()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 132 instructions, 9–124 executed per call, 4 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 8

8 hooks fire while WP_Customize_Manager::trash_changeset_post() runs, in this order:

  1. apply_filters( pre_trash_post )filterline 3093 (+21 into the body)

    Filters whether a post trashing should take place.

  2. do_action( wp_trash_post )actionline 3099 (+27 into the body)

    Fires before a post is sent to the Trash.

  3. do_action( edit_post_{$post->post_type} )actionline 3112 (+40 into the body)

    Fires once an existing post has been updated.

  4. do_action( edit_post )actionline 3115 (+43 into the body)

    Fires once an existing post has been updated.

  5. do_action( save_post_{$post->post_type} )actionline 3118 (+46 into the body)

    Fires once a post has been saved.

  6. do_action( save_post )actionline 3121 (+49 into the body)

    Fires once a post has been saved.

  7. do_action( wp_insert_post )actionline 3124 (+52 into the body)

    Fires once a post has been saved.

  8. do_action( trashed_post )actionline 3131 (+59 into the body)

    Fires after a post is sent to the Trash.

Uses · 10

Used by · 1

Source code

	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;		} 		$previous_status = $post->post_status; 		/** This filter is documented in wp-includes/post.php */		$check = apply_filters( 'pre_trash_post', null, $post, $previous_status );		if ( null !== $check ) {			return $check;		} 		/** This action is documented in wp-includes/post.php */		do_action( 'wp_trash_post', $post_id, $previous_status ); 		add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status );		add_post_meta( $post_id, '_wp_trash_meta_time', time() ); 		$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, $previous_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, $previous_status ); 		return $post;	}

Changelog

Introduced in 4.9.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-customize-manager.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.