daily pastebin goal
20%
SHARE
TWEET

WPUF Delete

damienoneill2001 Mar 31st, 2015 3 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.      * Delete a post
  3.      *
  4.      * Only post author and editors has the capability to delete a post
  5.      */
  6.     function delete_post() {
  7.         global $userdata;
  8.  
  9.         $nonce = $_REQUEST['_wpnonce'];
  10.         if ( !wp_verify_nonce( $nonce, 'wpuf_del' ) ) {
  11.             die( "Security check" );
  12.         }
  13.  
  14.         //check, if the requested user is the post author
  15.         $maybe_delete = get_post( $_REQUEST['pid'] );
  16.  
  17.         if ( ($maybe_delete->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
  18.             wp_delete_post( $_REQUEST['pid'] );
  19.  
  20.             //redirect
  21.             $redirect = add_query_arg( array('msg' => 'deleted'), get_permalink() );
  22.             wp_redirect( $redirect );
  23.         } else {
  24.             echo '<div class="error">' . __( 'You are not the post author. Cheeting huh!', 'wpuf' ) . '</div>';
  25.         }
  26.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top