wp_add_trashed_suffix_to_post_name_for_post( WP_Post $post ): string
- Since
- 4.5.0
- Source
wp-includes/post.php:8613
Description
Store its desired (i.e. current) slug so it can try to reclaim it if the post is untrashed.
For internal use.
Compatibility
- WordPress
- since 4.5.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
$postWP_Post- The post.
Return value
string- New slug for the post.
Performance profile
How much work a call to wp_add_trashed_suffix_to_post_name_for_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
- 14–44
- Plugin surface
- None
- Called by
- 2
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 46.
Nothing here hands control to plugin code.
2 places 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 - cacheobject cache
wp_cache_delete()one call below wp_add_trashed_suffix_to_post_name_for_post() - hookthird-party callbacks
do_action()one call below wp_add_trashed_suffix_to_post_name_for_post()
Further down the call graph this can also reach serialize, option and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_add_trashed_suffix_to_post_name_for_post() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
str_ends_with() | 14 | get_post(), str_ends_with() |
!str_ends_with() | 44 | get_post(), str_ends_with(), add_post_meta(), _truncate_post_slug(), ID(), clean_post_cache() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 46 | 14–44 | 1 | |
| 8.5 | 46 | 14–44 | 1 | |
| 8.4 | 46 | 14–44 | 1 | |
| 8.3 | 46 | 14–44 | 1 | |
| 8.2 | 46 | 14–44 | 1 | |
| 8.1 | 46 | 14–44 | 1 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 47 | 15–45 | 1 |
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.
Uses · 5
- get_post()Retrieves post data given a post ID or post object.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- add_post_meta()Adds a meta field to the given post.
- _truncate_post_slug()Truncates a post slug.
- clean_post_cache()Will clean the post in the cache.
Used by · 2
- wp_add_trashed_suffix_to_post_name_for_trashed_posts()Adds a suffix if any trashed posts have a given slug.
- wp_insert_post()Inserts or updates a post in the database.
Source code
function wp_add_trashed_suffix_to_post_name_for_post( $post ) { global $wpdb; $post = get_post( $post ); if ( str_ends_with( $post->post_name, '__trashed' ) ) { return $post->post_name; } add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name ); $post_name = _truncate_post_slug( $post->post_name, 191 ) . '__trashed'; $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); clean_post_cache( $post->ID ); return $post_name;}Changelog
Introduced in 4.5.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/post.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.