WordPress.org

Make WordPress Core

Ticket #21431: 21431.2.diff

File 21431.2.diff, 3.0 KB (added by westi, 18 months ago)

Updates diff against current trunk

  • wp-includes/post.php

     
    44314431 * @param string $post_type Post type. 
    44324432 * @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term. 
    44334433 * @param int $post_author Optional. Query posts having a single author ID. 
     4434 * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user.  Default is false. 
    44344435 * @return string SQL WHERE code that can be added to a query. 
    44354436 */ 
    4436 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) { 
     4437function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { 
    44374438        global $user_ID, $wpdb; 
    44384439 
    44394440        // Private posts 
     
    44574458 
    44584459        $sql .= "(post_status = 'publish'"; 
    44594460 
    4460         if ( current_user_can( $cap ) ) { 
    4461                 // Does the user have the capability to view private posts? Guess so. 
    4462                 $sql .= " OR post_status = 'private'"; 
    4463         } elseif ( is_user_logged_in() ) { 
    4464                 // Users can view their own private posts. 
    4465                 $id = (int) $user_ID; 
    4466                 if ( null === $post_author || ! $full ) { 
    4467                         $sql .= " OR post_status = 'private' AND post_author = $id"; 
    4468                 } elseif ( $id == (int) $post_author ) { 
     4461        // Only need to check the cap if $public_only is false 
     4462        if ( false === $public_only ) { 
     4463                if ( current_user_can( $cap ) ) { 
     4464                        // Does the user have the capability to view private posts? Guess so. 
    44694465                        $sql .= " OR post_status = 'private'"; 
     4466                } elseif ( is_user_logged_in() ) { 
     4467                        // Users can view their own private posts. 
     4468                        $id = (int) $user_ID; 
     4469                        if ( null === $post_author || ! $full ) { 
     4470                                $sql .= " OR post_status = 'private' AND post_author = $id"; 
     4471                        } elseif ( $id == (int) $post_author ) { 
     4472                                $sql .= " OR post_status = 'private'"; 
     4473                        } // else none 
    44704474                } // else none 
    4471         } // else none 
     4475        } 
    44724476 
    44734477        $sql .= ')'; 
    44744478 
  • wp-includes/user.php

     
    166166 * 
    167167 * @param array $users Array of user IDs. 
    168168 * @param string $post_type Optional. Post type to check. Defaults to post. 
     169 * @param bool $public_only Optional. Only return counts for public posts.  Defaults to false. 
    169170 * @return array Amount of posts each user has written. 
    170171 */ 
    171 function count_many_users_posts( $users, $post_type = 'post' ) { 
     172function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { 
    172173        global $wpdb; 
    173174 
    174175        $count = array(); 
     
    176177                return $count; 
    177178 
    178179        $userlist = implode( ',', array_map( 'absint', $users ) ); 
    179         $where = get_posts_by_author_sql( $post_type ); 
     180        $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); 
    180181 
    181182        $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); 
    182183        foreach ( $result as $row ) {