Advertisement
damienoneill2001

WPUF Delete

Mar 31st, 2015
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  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.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement