Ticket #14405: 14405.transient.1.diff

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

use a transient instead of persistent cache

Line 
1Index: wp-includes/author-template.php
2===================================================================
3--- wp-includes/author-template.php     (revision 17784)
4+++ wp-includes/author-template.php     (working copy)
5@@ -368,4 +368,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 = get_transient( '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+               set_transient( 'is_multi_author_posts', $is_multi_author, 86400 );
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+       delete_transient( 'is_multi_author_posts' );
35+}
36+add_action( 'transition_post_status', '__clear_multi_author_cache' );
37+
38 ?>