On this page
get_delete_post_link( int|WP_Post $post, string $deprecated = '', bool $force_delete = false ): string|void
Retrieves the delete posts link for post.
Description
Can be used within the WordPress loop or outside of it, with any post type.
Parameters
$postint|WP_Post Optional-
Post ID or post object. Default is the global
$post. $deprecatedstring Optional-
Not used.
Default:
'' $force_deletebool Optional-
Whether to bypass Trash and force deletion.
Default:
false
Return
string|void The delete post link URL for the given post.
Source
File: wp-includes/link-template.php. View all references
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 );
}
Hooks
- apply_filters( 'get_delete_post_link',
string $link ,int $post_id ,bool $force_delete ) -
Filters the post delete link.
Related
Uses
| Uses | Description |
|---|---|
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| _deprecated_argument() wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. |
| wp_nonce_url() wp-includes/functions.php | Retrieves URL with nonce added to URL query. |
| add_query_arg() wp-includes/functions.php | Retrieves a modified URL query string. |
| admin_url() wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
| get_post_type_object() wp-includes/post.php | Retrieves a post type object by name. |
Used By
| Used By | Description |
|---|---|
| WP_Posts_List_Table::handle_row_actions() wp-admin/includes/class-wp-posts-list-table.php | Generates and displays row action links. |
| post_submit_meta_box() wp-admin/includes/meta-boxes.php | Displays post submit form fields. |
| attachment_submit_meta_box() wp-admin/includes/meta-boxes.php | Displays attachment submit form fields. |
Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_delete_post_link