WordPress.org

Make WordPress Core

Ticket #14405: is_multi_author_cached.2.14405.diff

File is_multi_author_cached.2.14405.diff, 1.1 KB (added by filosofo, 4 years ago)
  • wp-includes/author-template.php

     
    363363        echo $return; 
    364364} 
    365365 
     366/** 
     367 * Does this site have more than one author 
     368 *  
     369 * Checks to see if more than one author has published posts. 
     370 *  
     371 * @return bool Whether or not we have more than one author 
     372 */ 
     373function is_multi_author() { 
     374        global $wpdb; 
     375         
     376        if ( false == ( $is_multi_author = wp_cache_get('is_multi_author', 'posts') ) ) { 
     377                $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2"); 
     378                $is_multi_author = 1 < count( $rows ) ? 1 : 0; 
     379                wp_cache_set('is_multi_author', $is_multi_author, 'posts'); 
     380        } 
     381 
     382        return (bool) $is_multi_author; 
     383} 
     384 
     385/**  
     386 * Helper function to clear the cache for number of authors. 
     387 *  
     388 * @private 
     389 */ 
     390function __clear_multi_author_cache() { 
     391        wp_cache_delete('is_multi_author', 'posts'); 
     392} 
     393add_action('transition_post_status', '__clear_multi_author_cache'); 
     394 
    366395?>