mirror of
git://develop.git.wordpress.org/
synced 2025-02-27 10:02:43 +01:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@17901 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4f8b646e03
commit
a2c9d9247c
@ -368,4 +368,34 @@ function wp_list_authors($args = '') {
|
|||||||
echo $return;
|
echo $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this site have more than one author
|
||||||
|
*
|
||||||
|
* Checks to see if more than one author has published posts.
|
||||||
|
*
|
||||||
|
* @since 3.2
|
||||||
|
* @return bool Whether or not we have more than one author
|
||||||
|
*/
|
||||||
|
function is_multi_author() {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
if ( false === ( $is_multi_author = wp_cache_get('is_multi_author', 'posts') ) ) {
|
||||||
|
$rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
|
||||||
|
$is_multi_author = 1 < count( $rows ) ? 1 : 0;
|
||||||
|
wp_cache_set('is_multi_author', $is_multi_author, 'posts');
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bool) $is_multi_author;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to clear the cache for number of authors.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function __clear_multi_author_cache() {
|
||||||
|
wp_cache_delete('is_multi_author', 'posts');
|
||||||
|
}
|
||||||
|
add_action('transition_post_status', '__clear_multi_author_cache');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user