WordPress.org

Make WordPress Core

Ticket #14405: is-multi-author.diff

File is-multi-author.diff, 1.3 KB (added by iandstewart, 8 years ago)
  • wp-includes/author-template.php

     
    368368        echo $return;
    369369}
    370370
     371/**
     372 * Returns true if there is more than one user with a published post
     373 */
     374function is_multi_author() {
     375        global $wpdb;
     376
     377        $users = get_users_of_blog();
     378        $author_ids = array();
     379        $authors = '';
     380        foreach ( (array) $users as $user )
     381                $author_ids[] = $user->user_id;
     382        if ( count($author_ids) > 0  ) {
     383                $author_ids = implode(',', $author_ids );
     384                $authors = $wpdb->get_results( "SELECT ID, user_nicename from $wpdb->users WHERE ID IN($author_ids) " . "ORDER BY display_name" );
     385        } else {
     386                $authors = array();
     387        }
     388
     389        $author_count = array();
     390        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 )
     391                $author_count[$row->post_author] = $row->count;
     392
     393        $multiple_authors = '';
     394        foreach ( (array) $authors as $author ) {
     395                $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
     396               
     397                if ( $posts != 0 )
     398                        $multiple_authors = $multiple_authors + 1;
     399        }
     400       
     401        if ( $multiple_authors > 1 )
     402                return true;
     403       
     404        return false;
     405}
     406
    371407?>