Advertisement
Guest User

Untitled

a guest
Sep 15th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.88 KB | None | 0 0
  1. <?php
  2.  
  3. function __construct() {
  4.         add_shortcode( 'wpuf_dashboard', array($this, 'shortcode') );
  5.     }
  6.  
  7.     /**
  8.      * Handle's user dashboard functionality
  9.      *
  10.      * Insert shortcode [wpuf_dashboard] in a page to
  11.      * show the user dashboard
  12.      *
  13.      * @since 0.1
  14.      */
  15.     function shortcode( $atts ) {
  16.  
  17.         extract( shortcode_atts( array('post_type' => 'post'), $atts ) );
  18.  
  19.         ob_start();
  20.  
  21.         if ( is_user_logged_in() ) {
  22.             $this->post_listing( $post_type );
  23.         } else {
  24.             $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
  25.  
  26.             if ( empty( $message ) ) {
  27.                 $msg = sprintf( __( "This page is restricted. Please %s to view this page.", 'wpuf' ), wp_loginout( '', false ) );
  28.                 echo apply_filters( 'wpuf_dashboard_unauth', $msg, $post_type );
  29.             } else {
  30.                 echo $message;
  31.             }
  32.         }
  33.  
  34.         $content = ob_get_contents();
  35.         ob_end_clean();
  36.  
  37.         return $content;
  38.     }
  39.  
  40.  
  41. function post_listing( $post_type ) {
  42.         global $wpdb, $userdata, $post;
  43.  
  44.         $userdata = get_userdata( $userdata->ID );
  45.         $pagenum = isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : 1;
  46.  
  47.         //delete post
  48.         if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == "del" ) {
  49.             $this->delete_post();
  50.         }
  51.  
  52.         //show delete success message
  53.         if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'deleted' ) {
  54.             echo '<div class="success">' . __( 'Post Deleted', 'wpuf' ) . '</div>';
  55.         }
  56.  
  57.         $args = array(
  58.             'author' => get_current_user_id(),
  59.             'post_status' => array('draft', 'future', 'pending', 'publish', 'private' ),
  60.             'post_type' => $post_type,
  61.             'posts_per_page' => wpuf_get_option( 'per_page', 'wpuf_dashboard', 10 ),
  62.             'paged' => $pagenum
  63.         );
  64.  
  65.         $original_post = $post;
  66.         $dashboard_query = new WP_Query( apply_filters( 'wpuf_dashboard_query', $args ) );
  67.         $post_type_obj = get_post_type_object( $post_type );
  68. }
  69.  
  70.     function delete_post() {
  71.         global $userdata;
  72.  
  73.         $nonce = $_REQUEST['_wpnonce'];
  74.         if ( !wp_verify_nonce( $nonce, 'wpuf_del' ) ) {
  75.             die( "Security check" );
  76.         }
  77.  
  78.         //check, if the requested user is the post author
  79.         $maybe_delete = get_post( $_REQUEST['pid'] );
  80.  
  81.         if ( ($maybe_delete->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
  82.             wp_delete_post( $_REQUEST['pid'] );
  83.  
  84.             //redirect
  85.             $redirect = add_query_arg( array('msg' => 'deleted'), get_permalink() );
  86.             wp_redirect( $redirect );
  87.         } else {
  88.             echo '<div class="error">' . __( 'You are not the post author. Cheeting huh!', 'wpuf' ) . '</div>';
  89.         }
  90.     }
  91.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement