WP_Customize_Manager::trash_changeset_post( int|WP_Post $post ): mixed
- Since
- 4.9.0
- Source
wp-includes/class-wp-customize-manager.php:3072
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
- Scaling
- Constant
- Instructions
- 9–124
- Plugin surface
- 8 hooks
- Called by
- 1
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 132.
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.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_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.
| When | Instructions | Calls it makes |
|---|---|---|
!($post instanceof) | 9 | get_post() |
$post instanceof | 16 | get_post(), wp_delete_post() |
$post instanceof | 17 | get_post(), get_post_status() |
$post instanceof && $check !== null | 27 | get_post(), get_post_status(), apply_filters() |
$post instanceof && $check === null | 124 | get_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:
- apply_filters( pre_trash_post )filterline 3093 (+21 into the body)
Filters whether a post trashing should take place.
- do_action( wp_trash_post )actionline 3099 (+27 into the body)
Fires before a post is sent to the Trash.
- do_action( edit_post_{$post->post_type} )actionline 3112 (+40 into the body)
Fires once an existing post has been updated.
- do_action( edit_post )actionline 3115 (+43 into the body)
Fires once an existing post has been updated.
- do_action( save_post_{$post->post_type} )actionline 3118 (+46 into the body)
Fires once a post has been saved.
- do_action( trashed_post )actionline 3131 (+59 into the body)
Fires after a post is sent to the Trash.
Uses · 10
- get_post()Retrieves post data given a post ID or post object.
- wp_delete_post()Trashes or deletes a post or page.
- get_post_status()Retrieves the post status based on the post ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- do_action()Calls the callback functions that have been added to an action hook.
- add_post_meta()Adds a meta field to the given post.
- clean_post_cache()Will clean the post in the cache.
- wp_transition_post_status()Fires actions related to the transitioning of a post's status.
- wp_after_insert_post()Fires actions after a post, its terms and meta data has been saved.
- wp_trash_post_comments()Moves comments for a post to the Trash.
Used by · 1
- WP_Customize_Manager::handle_changeset_trash_request()Handles request to trash a changeset.
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.
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.