Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42201 r42343  
    2121 * @return string|null The author's display name.
    2222 */
    23 function get_the_author($deprecated = '') {
     23function get_the_author( $deprecated = '' ) {
    2424    global $authordata;
    2525
    26     if ( !empty( $deprecated ) )
     26    if ( ! empty( $deprecated ) ) {
    2727        _deprecated_argument( __FUNCTION__, '2.1.0' );
     28    }
    2829
    2930    /**
     
    3435     * @param string $authordata->display_name The author's display name.
    3536     */
    36     return apply_filters('the_author', is_object($authordata) ? $authordata->display_name : null);
     37    return apply_filters( 'the_author', is_object( $authordata ) ? $authordata->display_name : null );
    3738}
    3839
     
    6263
    6364    if ( true !== $deprecated_echo ) {
    64         _deprecated_argument( __FUNCTION__, '1.5.0',
     65        _deprecated_argument(
     66            __FUNCTION__, '1.5.0',
    6567            /* translators: %s: get_the_author() */
    66             sprintf( __( 'Use %s instead if you do not want the value echoed.' ),
     68            sprintf(
     69                __( 'Use %s instead if you do not want the value echoed.' ),
    6770                '<code>get_the_author()</code>'
    6871            )
     
    8588 */
    8689function get_the_modified_author() {
    87     if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) {
    88         $last_user = get_userdata($last_id);
     90    if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true ) ) {
     91        $last_user = get_userdata( $last_id );
    8992
    9093        /**
     
    9598         * @param string $last_user->display_name The author's display name.
    9699         */
    97         return apply_filters('the_modified_author', $last_user->display_name);
     100        return apply_filters( 'the_modified_author', $last_user->display_name );
    98101    }
    99102}
     
    162165    }
    163166
    164     if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) )
     167    if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) {
    165168        $field = 'user_' . $field;
     169    }
    166170
    167171    $value = isset( $authordata->$field ) ? $authordata->$field : '';
     
    221225 */
    222226function get_the_author_link() {
    223     if ( get_the_author_meta('url') ) {
    224         return sprintf( '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
    225             esc_url( get_the_author_meta('url') ),
     227    if ( get_the_author_meta( 'url' ) ) {
     228        return sprintf(
     229            '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
     230            esc_url( get_the_author_meta( 'url' ) ),
    226231            /* translators: %s: author's display name */
    227232            esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), get_the_author() ) ),
     
    289294    }
    290295
    291     $link = sprintf( '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
     296    $link = sprintf(
     297        '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
    292298        esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
    293299        /* translators: %s: author's display name */
     
    335341    global $wp_rewrite;
    336342    $auth_ID = (int) $author_id;
    337     $link = $wp_rewrite->get_author_permastruct();
    338 
    339     if ( empty($link) ) {
     343    $link    = $wp_rewrite->get_author_permastruct();
     344
     345    if ( empty( $link ) ) {
    340346        $file = home_url( '/' );
    341347        $link = $file . '?author=' . $auth_ID;
    342348    } else {
    343349        if ( '' == $author_nicename ) {
    344             $user = get_userdata($author_id);
    345             if ( !empty($user->user_nicename) )
     350            $user = get_userdata( $author_id );
     351            if ( ! empty( $user->user_nicename ) ) {
    346352                $author_nicename = $user->user_nicename;
    347         }
    348         $link = str_replace('%author%', $author_nicename, $link);
     353            }
     354        }
     355        $link = str_replace( '%author%', $author_nicename, $link );
    349356        $link = home_url( user_trailingslashit( $link ) );
    350357    }
     
    403410
    404411    $defaults = array(
    405         'orderby' => 'name', 'order' => 'ASC', 'number' => '',
    406         'optioncount' => false, 'exclude_admin' => true,
    407         'show_fullname' => false, 'hide_empty' => true,
    408         'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
    409         'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
     412        'orderby'       => 'name',
     413        'order'         => 'ASC',
     414        'number'        => '',
     415        'optioncount'   => false,
     416        'exclude_admin' => true,
     417        'show_fullname' => false,
     418        'hide_empty'    => true,
     419        'feed'          => '',
     420        'feed_image'    => '',
     421        'feed_type'     => '',
     422        'echo'          => true,
     423        'style'         => 'list',
     424        'html'          => true,
     425        'exclude'       => '',
     426        'include'       => '',
    410427    );
    411428
     
    414431    $return = '';
    415432
    416     $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
     433    $query_args           = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
    417434    $query_args['fields'] = 'ids';
    418     $authors = get_users( $query_args );
     435    $authors              = get_users( $query_args );
    419436
    420437    $author_count = array();
    421     foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) {
    422         $author_count[$row->post_author] = $row->count;
     438    foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . ' GROUP BY post_author' ) as $row ) {
     439        $author_count[ $row->post_author ] = $row->count;
    423440    }
    424441    foreach ( $authors as $author_id ) {
     
    429446        }
    430447
    431         $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
     448        $posts = isset( $author_count[ $author->ID ] ) ? $author_count[ $author->ID ] : 0;
    432449
    433450        if ( ! $posts && $args['hide_empty'] ) {
     
    451468        }
    452469
    453         $link = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',
     470        $link = sprintf(
     471            '<a href="%1$s" title="%2$s">%3$s</a>',
    454472            get_author_posts_url( $author->ID, $author->user_nicename ),
    455473            /* translators: %s: author's display name */
     
    468486            $alt = '';
    469487            if ( ! empty( $args['feed'] ) ) {
    470                 $alt = ' alt="' . esc_attr( $args['feed'] ) . '"';
     488                $alt  = ' alt="' . esc_attr( $args['feed'] ) . '"';
    471489                $name = $args['feed'];
    472490            }
     
    488506
    489507        if ( $args['optioncount'] ) {
    490             $link .= ' ('. $posts . ')';
     508            $link .= ' (' . $posts . ')';
    491509        }
    492510
     
    518536
    519537    if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) {
    520         $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
     538        $rows            = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2" );
    521539        $is_multi_author = 1 < count( $rows ) ? 1 : 0;
    522540        set_transient( 'is_multi_author', $is_multi_author );
Note: See TracChangeset for help on using the changeset viewer.