Ticket #14405: is_multi_author_cached.2.14405.diff

File is_multi_author_cached.2.14405.diff, 1.1 KB (added by filosofo, 3 years ago)
Line 
1Index: wp-includes/author-template.php
2===================================================================
3--- wp-includes/author-template.php     (revision 15869)
4+++ wp-includes/author-template.php     (working copy)
5@@ -363,4 +363,33 @@
6        echo $return;
7 }
8 
9+/**
10+ * Does this site have more than one author
11+ *
12+ * Checks to see if more than one author has published posts.
13+ *
14+ * @return bool Whether or not we have more than one author
15+ */
16+function is_multi_author() {
17+       global $wpdb;
18+       
19+       if ( false == ( $is_multi_author = wp_cache_get('is_multi_author', 'posts') ) ) {
20+               $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
21+               $is_multi_author = 1 < count( $rows ) ? 1 : 0;
22+               wp_cache_set('is_multi_author', $is_multi_author, 'posts');
23+       }
24+
25+       return (bool) $is_multi_author;
26+}
27+
28+/**
29+ * Helper function to clear the cache for number of authors.
30+ *
31+ * @private
32+ */
33+function __clear_multi_author_cache() {
34+       wp_cache_delete('is_multi_author', 'posts');
35+}
36+add_action('transition_post_status', '__clear_multi_author_cache');
37+
38 ?>