wp_ajax_delete_post

Ajax handler for deleting a post.

Description

wp_ajax_delete_post( (string) $action ); 

Parameters (1)

0. $action (string)
Action to perform.

Usage

  1. if ( !function_exists( 'wp_ajax_delete_post' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4. // Action to perform. 
  5. $action = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_ajax_delete_post($action); 
  9.  

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_delete_post( $action ) { 
  2. if ( empty( $action ) ) 
  3. $action = 'delete-post'; 
  4. $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 
  5.  
  6. check_ajax_referer( "{$action}_$id" ); 
  7. if ( !current_user_can( 'delete_post', $id ) ) 
  8. wp_die( -1 ); 
  9.  
  10. if ( !get_post( $id ) ) 
  11. wp_die( 1 ); 
  12.  
  13. if ( wp_delete_post( $id ) ) 
  14. wp_die( 1 ); 
  15. else 
  16. wp_die( 0 );