Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Dashboard class
- *
- * @author Tareq Hasan
- * @package WP User Frontend
- */
- class WPUF_Frontend_Dashboard {
- 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;
- }
- /**
- * List's all the posts by the user
- *
- * @global object $wpdb
- * @global object $userdata
- */
- 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 );
- ?>
- <?php $user_id = get_current_user_id(); ?>
- <?php $user_info = get_userdata($user_id); ?>
- <div style="width: 700px; margin:0 0 10px 0;">
- <div style="float: left; width: 100px; border-right:1px solid #ddd; padding-right:5px;"><?php echo get_avatar( $user_id, $size = '100', $default = 'http://cdn.sakuhetu.com/imgs/global/No-Pic.jpg' ); ?></div>
- <div style="float: left; width: 575px; padding-left:5px; margin-top:-5px;">
- <strong><?php echo $user_info-> user_firstname; ?></strong>, You have Created
- <strong style="color:#F00;"><?php function countUserPosts($user_id) {$userposts = get_posts('post_status=any&showposts=-1&author='.$user_id); return count($userposts);} echo countUserPosts($user_id); ?></strong> Post(s), since <strong><?php echo date("F j, Y", strtotime(get_userdata(get_current_user_id( ))->user_registered)); ?></strong>.
- <br /> Address: <?php echo $user_info-> address; ?>
- <br /> Mobile: <?php echo $user_info-> mobile; ?>
- <br /> Phone: <?php echo $user_info-> phone; ?>
- <br /> <a title="Edit My Profile" href="<?php bloginfo('url'); ?>/edit-my-profile">Edit My Profile</a>
- </div>
- <br style="clear: left;" />
- </div>
- <h1>My Posts</h1>
- <div id="tabs" class="htabs">
- <a href="#published">Published Posts</a>
- <a href="#pending">Pending Reviews</a>
- <a href="#draft">Saved In Draft</a>
- </div>
- <div id="published" class="tab-content">
- <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts($paged . '&showposts=10&author='.$user_id.'&paged=$paged&post_status=publish'); ?>
- <?php while (have_posts()) : the_post();?>
- <div class="product-list">
- <div>
- <div class="inner">
- <div style="width: 825px;">
- <div style="float: left; width: 110px;">
- <div class="image">
- <?php
- if ( has_post_thumbnail()) {
- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
- echo '<a href="'.get_permalink().'" title="'.get_the_title(). '" >';
- the_post_thumbnail('thumbnail');
- echo '</a>';
- } else { ?>
- <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><img src="http://www.ekarnal.com/wp-content/uploads/2013/09/no-img-100x100.jpg" width="100" height="100" alt="No Image Available" /></a>
- <?php }?>
- </div>
- </div>
- <div style="float: left; width: 640px; padding-left:5px;">
- <div class="name" style="margin-bottom:-1px; text-transform:capitalize;"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
- <div style="border-bottom:1px solid #ddd; padding-bottom:5px; width:615px; text-transform:capitalize;"><?php trimcont(95); ?> ... »</div>
- <div style="margin-top:20px;">
- <?php if ( in_category( '330' )) { ?>
- <a class="hrefbutton" style="background:#f00;" onclick="return false">This Listing Is Expired</a>
- <?php } else { ?>
- <a href="<?php echo wp_nonce_url('edit-the-post?pid='.get_the_ID().''); ?>" class="hrefbutton" style="background:#4692F7;" title="Edit">Edit This Listing</a>
- <?php
- ?>
- <?php $del_url = add_query_arg( array('action' => 'del', 'pid' => $post->ID) ); ?>
- <a onclick="return confirm('Are you sure to delete this post?');" href="<?php echo wp_nonce_url( $del_url, 'wpuf_del' ) ?>" class="hrefbutton" style="background-color:#F00;" title="Delete">Delete</a>
- <?php } ?>
- </div>
- </div>
- <br style="clear: left;" />
- </div>
- </div>
- </div>
- </div>
- <?php endwhile; ?>
- <div style="float:right;"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></div>
- <?php wp_reset_query(); ?></div>
- <div id="pending" class="tab-content">
- <?php query_posts('showposts=-1&author='.$user_id.'&post_status=pending'); ?>
- <?php while (have_posts()) : the_post();?>
- <div class="product-list">
- <div>
- <div class="inner">
- <div style="width: 825px;">
- <div style="float: left; width: 110px;">
- <div class="image">
- <?php
- if ( has_post_thumbnail()) {
- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
- echo '<a href="'.get_permalink().'" title="'.get_the_title(). '" >';
- the_post_thumbnail('thumbnail');
- echo '</a>';
- } else { ?>
- <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><img src="http://www.ekarnal.com/wp-content/uploads/2013/09/no-img-100x100.jpg" width="100" height="100" alt="No Image Available" /></a>
- <?php }?>
- </div>
- </div>
- <div style="float: left; width: 640px; padding-left:5px;">
- <div class="name" style="margin-bottom:-1px; text-transform:capitalize;"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
- <div style="border-bottom:1px solid #ddd; padding-bottom:5px; width:615px; text-transform:capitalize;"><?php trimcont(95); ?> ... »</div>
- <div style="margin-top:20px;">
- <a href="<?php echo wp_nonce_url('edit-the-post?pid='.get_the_ID().''); ?>" class="hrefbutton" style="background:#4692F7;" title="Edit">Edit This Listing</a>
- <a onclick="return confirm('Are you sure to delete this post?');" href="<?php echo wp_nonce_url( $del_url, 'wpuf_del' ) ?>" class="hrefbutton" style="background-color:#F00;" title="Delete">Delete</a>
- </div>
- </div>
- <br style="clear: left;" />
- </div>
- </div>
- </div>
- </div>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </div>
- <div id="draft" class="tab-content">
- <?php query_posts('showposts=-1&author='.$user_id.'&post_status=draft'); ?>
- <?php while (have_posts()) : the_post();?>
- <div class="product-list">
- <div>
- <div class="inner">
- <div style="width: 825px;">
- <div style="float: left; width: 110px;">
- <div class="image">
- <?php
- if ( has_post_thumbnail()) {
- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
- echo '<a href="'.get_permalink().'" title="'.get_the_title(). '" >';
- the_post_thumbnail('thumbnail');
- echo '</a>';
- } else { ?>
- <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><img src="http://www.ekarnal.com/wp-content/uploads/2013/09/no-img-100x100.jpg" width="100" height="100" alt="No Image Available" /></a>
- <?php }?>
- </div>
- </div>
- <div style="float: left; width: 640px; padding-left:5px;">
- <div class="name" style="margin-bottom:-1px; text-transform:capitalize;"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
- <div style="border-bottom:1px solid #ddd; padding-bottom:5px; width:615px; text-transform:capitalize;"><?php trimcont(95); ?> ... »</div>
- <div style="margin-top:20px;">
- <a href="<?php echo wp_nonce_url('edit-the-post?pid='.get_the_ID().''); ?>" class="hrefbutton" style="background:#4692F7;" title="Edit">Edit This Listing</a>
- <a onclick="return confirm('Are you sure to delete this post?');" href="<?php echo wp_nonce_url('my-dashboard?action=del&pid='.get_the_ID().''); ?>" class="hrefbutton" style="background-color:#F00;" title="Delete">Delete</a>
- </div>
- </div>
- <br style="clear: left;" />
- </div>
- </div>
- </div>
- </div>
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </div>
- <?php
- }
- 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