wp_ajax_trash_post

Ajax handler for sending a post to the trash.

Description

wp_ajax_trash_post( (string) $action ); 

Parameters (1)

0. $action (string)
Action to perform.

Usage

  1. if ( !function_exists( 'wp_ajax_trash_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_trash_post($action); 
  9.  

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_trash_post( $action ) { 
  2. if ( empty( $action ) ) 
  3. $action = 'trash-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 ( 'trash-post' == $action ) 
  14. $done = wp_trash_post( $id ); 
  15. else 
  16. $done = wp_untrash_post( $id ); 
  17.  
  18. if ( $done ) 
  19. wp_die( 1 ); 
  20.  
  21. wp_die( 0 );