WordPress.org

Make WordPress Core

Ticket #18791: 18791.2.patch

File 18791.2.patch, 5.4 KB (added by DrewAPicture, 5 years ago)

docs + single post type only

  • src/wp-includes/author-template.php

     
    324324 * <li>include (array): Array of user IDs to explicitly include.</li>
    325325 * </ul>
    326326 *
     327 * @todo Document default arguments.
     328 *
     329 * @since 1.2.0
     330 * @since 4.0.0 'post_type' argument added.
     331 *
    327332 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors
    328  * @since 1.2.0
     333 *
    329334 * @param array $args The argument array.
    330335 * @return null|string The output, if echo is set to false.
    331336 */
     
    336341                'orderby' => 'name', 'order' => 'ASC', 'number' => '',
    337342                'optioncount' => false, 'exclude_admin' => true,
    338343                'show_fullname' => false, 'hide_empty' => true,
    339                 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
    340                 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
     344                'feed' => '', 'feed_image' => '', 'feed_type' => '',
     345                'post_type' => 'post', 'echo' => true, 'style' => 'list',
     346                'html' => true, 'exclude' => '', 'include' => ''
    341347        );
    342348
    343349        $args = wp_parse_args( $args, $defaults );
     
    348354        $query_args['fields'] = 'ids';
    349355        $authors = get_users( $query_args );
    350356
     357        $post_type_where = 'post_type = ' . sanitize_key( $args['post_type'] );
     358
    351359        $author_count = array();
    352         foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) {
     360
     361        $results = $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE $post_type_where " . get_private_posts_cap_sql( 'any' ) . " GROUP BY post_author" );
     362
     363        foreach ( (array) $results as $row ) {
    353364                $author_count[$row->post_author] = $row->count;
    354365        }
     366
    355367        foreach ( $authors as $author_id ) {
    356368                $author = get_userdata( $author_id );
    357369
     
    434446 * Checks to see if more than one author has published posts.
    435447 *
    436448 * @since 3.2.0
     449 *
    437450 * @return bool Whether or not we have more than one author
    438451 */
    439452function is_multi_author() {
    440453        global $wpdb;
    441454
    442455        if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) {
    443                 $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
     456                $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status = 'publish' LIMIT 2");
    444457                $is_multi_author = 1 < count( $rows ) ? 1 : 0;
    445458                set_transient( 'is_multi_author', $is_multi_author );
    446459        }
  • src/wp-includes/post.php

     
    52085208/**
    52095209 * Retrieve the post SQL based on capability, author, and type.
    52105210 *
     5211 * @since 3.0.0
     5212 *
    52115213 * @see get_private_posts_cap_sql() for full description.
    52125214 *
    5213  * @since 3.0.0
    5214  * @param string $post_type Post type.
    5215  * @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term.
    5216  * @param int $post_author Optional. Query posts having a single author ID.
    5217  * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user.  Default is false.
     5215 * @param string $post_type   Optional. Post type. Default 'post'.
     5216 * @param bool   $full        Optional. Returns a full WHERE statement instead of just an 'andalso' term.
     5217 * @param int    $post_author Optional. Query posts having a single author ID.
     5218 * @param bool   $public_only Optional. Only return public posts. Skips cap checks for $current_user.
     5219 *                            Default is false.
    52185220 * @return string SQL WHERE code that can be added to a query.
    52195221 */
    5220 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
     5222function get_posts_by_author_sql( $post_type = 'post', $full = true, $post_author = null, $public_only = false ) {
    52215223        global $wpdb;
    52225224
    52235225        // Private posts
     
    52385240                $cap = $post_type_obj->cap->read_private_posts;
    52395241        }
    52405242
     5243        $post_type_where = 'post_type = ' . sanitize_key( $post_type );
     5244
    52415245        if ( $full ) {
    52425246                if ( null === $post_author ) {
    5243                         $sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type );
     5247                        $sql = $wpdb->prepare( 'WHERE %s AND ', $post_type_where );
    52445248                } else {
    5245                         $sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type );
     5249                        $sql = $wpdb->prepare( 'WHERE post_author = %d AND %s AND ', $post_author, $post_type_where );
    52465250                }
    52475251        } else {
    52485252                $sql = '';
  • src/wp-includes/user.php

     
    253253 *
    254254 * @global wpdb $wpdb WordPress database object for queries.
    255255 *
    256  * @param int $userid User ID.
     256 * @param int    $userid    User ID.
     257 * @param string $post_type Optional. Post type. Default 'post'.
    257258 * @return int Amount of posts user has written.
    258259 */
    259 function count_user_posts($userid) {
     260function count_user_posts( $userid, $post_type = 'post' ) {
    260261        global $wpdb;
    261262
    262         $where = get_posts_by_author_sql('post', true, $userid);
     263        $where = get_posts_by_author_sql( $post_type, true, $userid );
    263264
    264265        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    265266