WordPress.org

Make WordPress Core

Ticket #14405: 14405.transient.1.diff

File 14405.transient.1.diff, 1.1 KB (added by wpmuguru, 3 years ago)

use a transient instead of persistent cache

  • wp-includes/author-template.php

     
    368368        echo $return; 
    369369} 
    370370 
     371/** 
     372 * Does this site have more than one author 
     373 *  
     374 * Checks to see if more than one author has published posts. 
     375 *  
     376 * @return bool Whether or not we have more than one author 
     377 */ 
     378function is_multi_author() { 
     379        global $wpdb; 
     380         
     381        if ( false === ( $is_multi_author = get_transient( 'is_multi_author_posts' ) ) ) { 
     382                $rows = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2" ); 
     383                $is_multi_author = 1 < count( $rows ) ? 1 : 0; 
     384                set_transient( 'is_multi_author_posts', $is_multi_author, 86400 ); 
     385        } 
     386 
     387        return (bool) $is_multi_author; 
     388} 
     389 
     390/**  
     391 * Helper function to clear the cache for number of authors. 
     392 *  
     393 * @private 
     394 */ 
     395function __clear_multi_author_cache() { 
     396        delete_transient( 'is_multi_author_posts' ); 
     397} 
     398add_action( 'transition_post_status', '__clear_multi_author_cache' ); 
     399 
    371400?>