get_delete_post_link( int|WP_Post $id, string $deprecated = ”, bool $force_delete = false )
Retrieves the delete posts link for post.
Description Description
Can be used within the WordPress loop or outside of it, with any post type.
Parameters Parameters
- $id
-
(int|WP_Post) (Optional) Post ID or post object. Default is the global
$post
. - $deprecated
-
(string) (Optional) Not used.
Default value: ”
- $force_delete
-
(bool) (Optional) Whether to bypass Trash and force deletion.
Default value: false
Return Return
(string|void) The delete post link URL for the given post.
Source Source
File: wp-includes/link-template.php
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 |
function get_delete_post_link( $id = 0, $deprecated = '' , $force_delete = false ) { if ( ! empty ( $deprecated ) ) { _deprecated_argument( __FUNCTION__ , '3.0.0' ); } $post = get_post( $id ); 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 ); } |
Expand full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.9.0 | Introduced. |