get_delete_post_link

Retrieves the delete posts link for post.

Description

(string|void) get_delete_post_link( (int) $id = 0, (string) $deprecated = '', (bool) $force_delete = false ); 

Can be used within the WordPress loop or outside of it, with any post type.

Returns (string|void)

The delete post link URL for the given post.

Parameters (3)

0. $id — Optional. (int)
Post ID. Default is the ID of the global $post..
1. $deprecated — Optional. (string) => ''
The deprecated.
2. $force_delete — Optional. (bool) => false
Whether to bypass trash and force deletion. Default false.

Usage

  1. if ( !function_exists( 'get_delete_post_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Post ID. Default is the ID of the global `$post`. 
  5. $id = -1; 
  6.  
  7. // The deprecated. 
  8. $deprecated = ''; 
  9.  
  10. // Optional. Whether to bypass trash and force deletion. Default false. 
  11. $force_delete = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_delete_post_link($id, $deprecated, $force_delete); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { 
  2. if ( ! empty( $deprecated ) ) 
  3. _deprecated_argument( __FUNCTION__, '3.0.0' ); 
  4.  
  5. if ( !$post = get_post( $id ) ) 
  6. return; 
  7.  
  8. $post_type_object = get_post_type_object( $post->post_type ); 
  9. if ( !$post_type_object ) 
  10. return; 
  11.  
  12. if ( !current_user_can( 'delete_post', $post->ID ) ) 
  13. return; 
  14.  
  15. $action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; 
  16.  
  17. $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); 
  18.  
  19. /** 
  20. * Filters the post delete link. 
  21. * @since 2.9.0 
  22. * @param string $link The delete link. 
  23. * @param int $post_id Post ID. 
  24. * @param bool $force_delete Whether to bypass the trash and force deletion. Default false. 
  25. */ 
  26. return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete );