WordPress.org

Make WordPress Core

Ticket #24284: author-templates.patch

File author-templates.patch, 2.6 KB (added by alex-ye, 7 years ago)

First Try :)

  • wp-includes/author-template.php

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: \wp-includes
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    369369 * @since 3.2.0
    370370 * @return bool Whether or not we have more than one author
    371371 */
    372 function is_multi_author() {
     372function is_multi_author( $args = '' ) {
    373373        global $wpdb;
    374374
    375         if ( false === ( $is_multi_author = wp_cache_get('is_multi_author', 'posts') ) ) {
    376                 $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
    377                 $is_multi_author = 1 < count( $rows ) ? 1 : 0;
    378                 wp_cache_set('is_multi_author', $is_multi_author, 'posts');
     375        $args = wp_parse_args( $args, array(
     376            'post_type' => 'post',
     377            'post_status' => 'publish',
     378        ));
     379
     380        if ( 'any' == strtolower( $args['post_type'] ) )
     381                $args['post_type'] = false;
     382
     383        if ( 'any' == strtolower( $args['post_status'] ) )
     384                $args['post_status'] = false;
     385
     386        $args = array_filter( $args );
     387
     388        // Get the cache key based on $args
     389        $key = md5( serialize( $args ) );
     390
     391        // Check for a cached check
     392        $is_multi_author = wp_cache_get( 'is_multi_author', 'posts' );
     393
     394        if ( ! is_array( $is_multi_author ) )
     395                $is_multi_author = array();
     396
     397        // If there is no cached check, let's do it
     398        if ( ! isset( $is_multi_author[$key] ) ) {
     399                $where = '';
     400
     401                // If the $args not empty, Build the WHERE string
     402                if ( ! empty( $args ) ) {
     403
     404                        $where = array();
     405
     406                        foreach ( array_keys( $args ) as $key )
     407                                $where[] = "{$key} = %s";
     408
     409                        $where = $wpdb->prepare( 'WHERE ' . implode( $where, ' AND ' ), array_values( $args ) );
     410
     411                } // end if
     412
     413                // Do the do
     414                $rows = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts {$where} LIMIT 2" );
     415                $is_multi_author[$key] = ( 1 < count( $rows ) ) ? 1 : 0;
     416
     417                // Cache the check result
     418                wp_cache_set( 'is_multi_author', $is_multi_author, 'posts' );
    379419        }
    380420
    381         return apply_filters( 'is_multi_author', (bool) $is_multi_author );
     421        return apply_filters( 'is_multi_author', (bool) $is_multi_author[$key] );
    382422}
    383423
    384424/**