From 7bf97e4ab20484bdfc50a18450ae5aeab409a6de Mon Sep 17 00:00:00 2001 From: scribu Date: Thu, 9 Sep 2010 22:22:36 +0000 Subject: [PATCH] Fix posts screen for contributors. Fixes #14822 git-svn-id: https://develop.svn.wordpress.org/trunk@15605 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/default-list-tables.php | 44 +++++++++++++---------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index c3a8315cf4..9749332387 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -29,8 +29,17 @@ class WP_Posts_Table extends WP_List_Table { */ var $comment_pending_count; + /** + * Holds the number of posts for this user + * + * @since 3.1.0 + * @var bool + * @access private + */ + var $user_posts_count; + function WP_Posts_Table() { - global $post_type_object, $post_type, $current_screen; + global $post_type_object, $post_type, $current_screen, $wpdb; if ( !isset( $_REQUEST['post_type'] ) ) $post_type = 'post'; @@ -42,6 +51,17 @@ class WP_Posts_Table extends WP_List_Table { $post_type_object = get_post_type_object( $post_type ); + if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) { + $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( " + SELECT COUNT( 1 ) FROM $wpdb->posts + WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' ) + AND post_author = %d + ", $post_type, get_current_user_id() ) ); + + if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) ) + $_GET['author'] = get_current_user_id(); + } + parent::WP_List_Table( array( 'screen' => $current_screen, 'plural' => 'posts', @@ -98,7 +118,7 @@ class WP_Posts_Table extends WP_List_Table { function get_views() { global $post_type, $post_type_object, $locked_post_status, $avail_post_stati; - + if ( !empty($locked_post_status) ) return array(); @@ -107,24 +127,12 @@ class WP_Posts_Table extends WP_List_Table { $class = ''; $allposts = ''; - $user_posts = false; - if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) { - $user_posts = true; + $current_user_id = get_current_user_id(); - $user_posts_count = $wpdb->get_var( $wpdb->prepare( " - SELECT COUNT( 1 ) FROM $wpdb->posts - WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' ) - AND post_author = %d - ", $post_type, get_current_user_id() ) ); - - if ( $user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) ) - $_REQUEST['author'] = get_current_user_id(); - } - - if ( $user_posts ) { - if ( isset( $_REQUEST['author'] ) && ( $_REQUEST['author'] == $current_user->ID ) ) + if ( $this->user_posts_count ) { + if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) $class = ' class="current"'; - $status_links['author'] = "
  • " . sprintf( _nx( 'Mine (%s)', 'Mine (%s)', $user_posts_count, 'posts' ), number_format_i18n( $user_posts_count ) ) . ''; + $status_links['mine'] = "
  • " . sprintf( _nx( 'Mine (%s)', 'Mine (%s)', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . ''; $allposts = '&all_posts=1'; }