Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function __construct() {
- add_shortcode( 'wpuf_dashboard', array($this, 'shortcode') );
- }
- /**
- * Handle's user dashboard functionality
- *
- * Insert shortcode [wpuf_dashboard] in a page to
- * show the user dashboard
- *
- * @since 0.1
- */
- function shortcode( $atts ) {
- extract( shortcode_atts( array('post_type' => 'post'), $atts ) );
- ob_start();
- if ( is_user_logged_in() ) {
- $this->post_listing( $post_type );
- } else {
- $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
- if ( empty( $message ) ) {
- $msg = sprintf( __( "This page is restricted. Please %s to view this page.", 'wpuf' ), wp_loginout( '', false ) );
- echo apply_filters( 'wpuf_dashboard_unauth', $msg, $post_type );
- } else {
- echo $message;
- }
- }
- $content = ob_get_contents();
- ob_end_clean();
- return $content;
- }
- function post_listing( $post_type ) {
- global $wpdb, $userdata, $post;
- $userdata = get_userdata( $userdata->ID );
- $pagenum = isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : 1;
- //delete post
- if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == "del" ) {
- $this->delete_post();
- }
- //show delete success message
- if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'deleted' ) {
- echo '<div class="success">' . __( 'Post Deleted', 'wpuf' ) . '</div>';
- }
- $args = array(
- 'author' => get_current_user_id(),
- 'post_status' => array('draft', 'future', 'pending', 'publish', 'private' ),
- 'post_type' => $post_type,
- 'posts_per_page' => wpuf_get_option( 'per_page', 'wpuf_dashboard', 10 ),
- 'paged' => $pagenum
- );
- $original_post = $post;
- $dashboard_query = new WP_Query( apply_filters( 'wpuf_dashboard_query', $args ) );
- $post_type_obj = get_post_type_object( $post_type );
- }
- function delete_post() {
- global $userdata;
- $nonce = $_REQUEST['_wpnonce'];
- if ( !wp_verify_nonce( $nonce, 'wpuf_del' ) ) {
- die( "Security check" );
- }
- //check, if the requested user is the post author
- $maybe_delete = get_post( $_REQUEST['pid'] );
- if ( ($maybe_delete->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
- wp_delete_post( $_REQUEST['pid'] );
- //redirect
- $redirect = add_query_arg( array('msg' => 'deleted'), get_permalink() );
- wp_redirect( $redirect );
- } else {
- echo '<div class="error">' . __( 'You are not the post author. Cheeting huh!', 'wpuf' ) . '</div>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement