Make WordPress Core


Ignore:
Timestamp:
09/09/2010 10:22:36 PM (16 years ago)
Author:
scribu
Message:

Fix posts screen for contributors. Fixes #14822

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/default-list-tables.php

    r15604 r15605  
    3030        var $comment_pending_count;
    3131
     32        /**
     33         * Holds the number of posts for this user
     34         *
     35         * @since 3.1.0
     36         * @var bool
     37         * @access private
     38         */
     39        var $user_posts_count;
     40
    3241        function WP_Posts_Table() {
    33                 global $post_type_object, $post_type, $current_screen;
     42                global $post_type_object, $post_type, $current_screen, $wpdb;
    3443
    3544                if ( !isset( $_REQUEST['post_type'] ) )
    … …  
    4352                $post_type_object = get_post_type_object( $post_type );
    4453
     54                if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
     55                        $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
     56                                SELECT COUNT( 1 ) FROM $wpdb->posts
     57                                WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' )
     58                                AND post_author = %d
     59                        ", $post_type, get_current_user_id() ) );
     60
     61                        if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) )
     62                                $_GET['author'] = get_current_user_id();
     63                }
     64
    4565                parent::WP_List_Table( array(
    4666                        'screen' => $current_screen,
    … …  
    99119        function get_views() {
    100120                global $post_type, $post_type_object, $locked_post_status, $avail_post_stati;
    101        
     121
    102122                if ( !empty($locked_post_status) )
    103123                        return array();
    … …  
    108128                $allposts = '';
    109129
    110                 $user_posts = false;
    111                 if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
    112                         $user_posts = true;
    113 
    114                         $user_posts_count = $wpdb->get_var( $wpdb->prepare( "
    115                                 SELECT COUNT( 1 ) FROM $wpdb->posts
    116                                 WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' )
    117                                 AND post_author = %d
    118                         ", $post_type, get_current_user_id() ) );
    119 
    120                         if ( $user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) )
    121                                 $_REQUEST['author'] = get_current_user_id();
    122                 }
    123 
    124                 if ( $user_posts ) {
    125                         if ( isset( $_REQUEST['author'] ) && ( $_REQUEST['author'] == $current_user->ID ) )
     130                $current_user_id = get_current_user_id();
     131
     132                if ( $this->user_posts_count ) {
     133                        if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
    126134                                $class = ' class="current"';
    127                         $status_links['author'] = "<li><a href='edit.php?post_type=$post_type&author=$current_user->ID'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $user_posts_count, 'posts' ), number_format_i18n( $user_posts_count ) ) . '</a>';
     135                        $status_links['mine'] = "<li><a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>';
    128136                        $allposts = '&all_posts=1';
    129137                }
Note: See TracChangeset for help on using the changeset viewer.