Make WordPress Core


Ignore:
Timestamp:
05/12/2011 07:14:44 AM (13 years ago)
Author:
westi
Message:

Introduce new is_multi_author() template tag to make it easier for themes to have different behaviour when a site has more than one
author. Fixes #14405 props filosofo.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/author-template.php

    r17548 r17901  
    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 * @since 3.2
     377 * @return bool Whether or not we have more than one author
     378 */
     379function is_multi_author() {
     380    global $wpdb;
     381   
     382    if ( false === ( $is_multi_author = wp_cache_get('is_multi_author', 'posts') ) ) {
     383        $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
     384        $is_multi_author = 1 < count( $rows ) ? 1 : 0;
     385        wp_cache_set('is_multi_author', $is_multi_author, 'posts');
     386    }
     387
     388    return (bool) $is_multi_author;
     389}
     390
     391/**
     392 * Helper function to clear the cache for number of authors.
     393 *
     394 * @private
     395 */
     396function __clear_multi_author_cache() {
     397    wp_cache_delete('is_multi_author', 'posts');
     398}
     399add_action('transition_post_status', '__clear_multi_author_cache');
     400
    371401?>
Note: See TracChangeset for help on using the changeset viewer.