get_delete_post_link( int|WP_Post $post = 0, string $deprecated = '', bool $force_delete = false ): string|void
- Since
- 2.9.0
- Source
wp-includes/link-template.php:1557
Description
Can be used within the WordPress loop or outside of it, with any post type.
Compatibility
- WordPress
- since 2.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_Postoptional- Post ID or post object. Default is the global
$post.Default:0 $deprecatedstringoptional- Not used.Default:
'' $force_deletebooloptional- Whether to bypass Trash and force deletion. Default false.Default:
false
Return value
string|void- The delete post link URL for the given post.
Performance profile
How much work a call to get_delete_post_link() 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
- 11–66
- Plugin surface
- 1 hook
- Called by
- 3
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 70.
Third-party callbacks on 'get_delete_post_link' run inside this call, and their cost is not bounded by anything here.
3 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 - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize 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 · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_delete_post_link() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($deprecated) | 11 | get_post() |
!empty($deprecated) | 15 | _deprecated_argument(), get_post() |
empty($deprecated) | 18 | get_post(), get_post_type_object() |
!empty($deprecated) | 22 | _deprecated_argument(), get_post(), get_post_type_object() |
empty($deprecated) && !current_user_can() | 25 | get_post(), get_post_type_object(), current_user_can() |
!empty($deprecated) && !current_user_can() | 29 | _deprecated_argument(), get_post(), get_post_type_object(), current_user_can() |
empty($deprecated) && current_user_can() | 60–62 | get_post(), get_post_type_object(), current_user_can(), sprintf(), admin_url(), add_query_arg(), wp_nonce_url(), apply_filters() |
!empty($deprecated) && current_user_can() | 64–66 | _deprecated_argument(), get_post(), get_post_type_object(), current_user_can(), sprintf(), admin_url(), add_query_arg(), wp_nonce_url(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 70 instructions, 11–66 executed per call, 6 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 · 1
One hook fires while get_delete_post_link() runs, in this order:
- apply_filters( get_delete_post_link )filterline 1591 (+34 into the body)
Filters the post delete link.
Uses · 8
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- get_post()Retrieves post data given a post ID or post object.
- get_post_type_object()Retrieves a post type object by name.
- current_user_can()Returns whether the current user has the specified capability.
- add_query_arg()Retrieves a modified URL query string.
- admin_url()Retrieves the URL to the admin area for the current site.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_nonce_url()Retrieves URL with nonce added to URL query.
Used by · 3
- WP_Posts_List_Table::handle_row_actions()Generates and displays row action links.
- attachment_submit_meta_box()Displays attachment submit form fields.
- post_submit_meta_box()Displays post submit form fields.
Source code
function get_delete_post_link( $post = 0, $deprecated = '', $force_delete = false ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '3.0.0' ); } $post = get_post( $post ); if ( ! $post ) { return; } $post_type_object = get_post_type_object( $post->post_type ); if ( ! $post_type_object ) { return; } if ( ! current_user_can( 'delete_post', $post->ID ) ) { return; } $action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); /** * Filters the post delete link. * * @since 2.9.0 * * @param string $link The delete link. * @param int $post_id Post ID. * @param bool $force_delete Whether to bypass the Trash and force deletion. Default false. */ return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete );}Changelog
Introduced in 2.9.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
string|void to string|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/link-template.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.