WordPress.org

Make WordPress Core

Changeset 34584


Ignore:
Timestamp:
09/26/2015 06:50:03 AM (6 years ago)
Author:
wonderboymusic
Message:

Posts List Table: check is_multi_author() before attempting to set ->user_posts_count. Also, don't show "Mine" when the count is the same as "All."

Fixes #19609.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r34383 r34584  
    8080        $post_type        = $this->screen->post_type;
    8181        $post_type_object = get_post_type_object( $post_type );
    82         $exclude_states   = get_post_stati( array(
    83             'show_in_admin_all_list' => false,
    84         ) );
    85         $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
    86             SELECT COUNT( 1 )
    87             FROM $wpdb->posts
    88             WHERE post_type = %s
    89             AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
    90             AND post_author = %d
    91         ", $post_type, get_current_user_id() ) );
     82
     83        if ( is_multi_author() ) {
     84            $exclude_states   = get_post_stati( array(
     85                'show_in_admin_all_list' => false,
     86            ) );
     87            $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
     88                SELECT COUNT( 1 )
     89                FROM $wpdb->posts
     90                WHERE post_type = %s
     91                AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
     92                AND post_author = %d
     93            ", $post_type, get_current_user_id() ) );
     94        }
    9295
    9396        if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
     
    261264        $status_links = array();
    262265        $num_posts = wp_count_posts( $post_type, 'readable' );
     266        $total_posts = array_sum( (array) $num_posts );
    263267        $class = '';
    264268
     
    267271        $mine = '';
    268272
    269         if ( $this->user_posts_count ) {
     273        if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
    270274            if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
    271275                $class = 'current';
     
    292296            $class = '';
    293297        }
    294 
    295         $total_posts = array_sum( (array) $num_posts );
    296298
    297299        // Subtract post types that are not included in the admin all list.
Note: See TracChangeset for help on using the changeset viewer.