WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (4 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-content/themes/twentytwelve/functions.php

    r41756 r42343  
    2424
    2525// Set up the content width value based on the theme's design and stylesheet.
    26 if ( ! isset( $content_width ) )
     26if ( ! isset( $content_width ) ) {
    2727    $content_width = 625;
     28}
    2829
    2930/**
     
    3637 * @uses add_editor_style() To add a Visual Editor stylesheet.
    3738 * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
    38  *  custom background, and post formats.
     39 *  custom background, and post formats.
    3940 * @uses register_nav_menu() To add support for navigation menus.
    4041 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
     
    6869     * and here we also set up the default background color.
    6970     */
    70     add_theme_support( 'custom-background', array(
    71         'default-color' => 'e6e6e6',
    72     ) );
     71    add_theme_support(
     72        'custom-background', array(
     73            'default-color' => 'e6e6e6',
     74        )
     75    );
    7376
    7477    // This theme uses a custom image size for featured images, displayed on "standard" posts.
     
    110113        $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
    111114
    112         if ( 'cyrillic' == $subset )
     115        if ( 'cyrillic' == $subset ) {
    113116            $subsets .= ',cyrillic,cyrillic-ext';
    114         elseif ( 'greek' == $subset )
     117        } elseif ( 'greek' == $subset ) {
    115118            $subsets .= ',greek,greek-ext';
    116         elseif ( 'vietnamese' == $subset )
     119        } elseif ( 'vietnamese' == $subset ) {
    117120            $subsets .= ',vietnamese';
     121        }
    118122
    119123        $query_args = array(
     
    121125            'subset' => $subsets,
    122126        );
    123         $font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
     127        $font_url   = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    124128    }
    125129
     
    139143     * sites with threaded comments (when in use).
    140144     */
    141     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
     145    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    142146        wp_enqueue_script( 'comment-reply' );
     147    }
    143148
    144149    // Adds JavaScript for handling the navigation menu hide-and-show behavior.
     
    146151
    147152    $font_url = twentytwelve_get_font_url();
    148     if ( ! empty( $font_url ) )
     153    if ( ! empty( $font_url ) ) {
    149154        wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
     155    }
    150156
    151157    // Loads our main stylesheet.
     
    198204    $font_url = twentytwelve_get_font_url();
    199205
    200     if ( empty( $font_url ) )
     206    if ( empty( $font_url ) ) {
    201207        return $mce_css;
    202 
    203     if ( ! empty( $mce_css ) )
     208    }
     209
     210    if ( ! empty( $mce_css ) ) {
    204211        $mce_css .= ',';
     212    }
    205213
    206214    $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
     
    225233    global $paged, $page;
    226234
    227     if ( is_feed() )
     235    if ( is_feed() ) {
    228236        return $title;
     237    }
    229238
    230239    // Add the site name.
     
    233242    // Add the site description for the home/front page.
    234243    $site_description = get_bloginfo( 'description', 'display' );
    235     if ( $site_description && ( is_home() || is_front_page() ) )
     244    if ( $site_description && ( is_home() || is_front_page() ) ) {
    236245        $title = "$title $sep $site_description";
     246    }
    237247
    238248    // Add a page number if necessary.
    239     if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() )
     249    if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    240250        $title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
     251    }
    241252
    242253    return $title;
     
    252263 */
    253264function twentytwelve_page_menu_args( $args ) {
    254     if ( ! isset( $args['show_home'] ) )
     265    if ( ! isset( $args['show_home'] ) ) {
    255266        $args['show_home'] = true;
     267    }
    256268    return $args;
    257269}
     
    266278 */
    267279function twentytwelve_widgets_init() {
    268     register_sidebar( array(
    269         'name' => __( 'Main Sidebar', 'twentytwelve' ),
    270         'id' => 'sidebar-1',
    271         'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
    272         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    273         'after_widget' => '</aside>',
    274         'before_title' => '<h3 class="widget-title">',
    275         'after_title' => '</h3>',
    276     ) );
    277 
    278     register_sidebar( array(
    279         'name' => __( 'First Front Page Widget Area', 'twentytwelve' ),
    280         'id' => 'sidebar-2',
    281         'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
    282         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    283         'after_widget' => '</aside>',
    284         'before_title' => '<h3 class="widget-title">',
    285         'after_title' => '</h3>',
    286     ) );
    287 
    288     register_sidebar( array(
    289         'name' => __( 'Second Front Page Widget Area', 'twentytwelve' ),
    290         'id' => 'sidebar-3',
    291         'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
    292         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    293         'after_widget' => '</aside>',
    294         'before_title' => '<h3 class="widget-title">',
    295         'after_title' => '</h3>',
    296     ) );
     280    register_sidebar(
     281        array(
     282            'name'          => __( 'Main Sidebar', 'twentytwelve' ),
     283            'id'            => 'sidebar-1',
     284            'description'   => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
     285            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     286            'after_widget'  => '</aside>',
     287            'before_title'  => '<h3 class="widget-title">',
     288            'after_title'   => '</h3>',
     289        )
     290    );
     291
     292    register_sidebar(
     293        array(
     294            'name'          => __( 'First Front Page Widget Area', 'twentytwelve' ),
     295            'id'            => 'sidebar-2',
     296            'description'   => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
     297            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     298            'after_widget'  => '</aside>',
     299            'before_title'  => '<h3 class="widget-title">',
     300            'after_title'   => '</h3>',
     301        )
     302    );
     303
     304    register_sidebar(
     305        array(
     306            'name'          => __( 'Second Front Page Widget Area', 'twentytwelve' ),
     307            'id'            => 'sidebar-3',
     308            'description'   => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
     309            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     310            'after_widget'  => '</aside>',
     311            'before_title'  => '<h3 class="widget-title">',
     312            'after_title'   => '</h3>',
     313        )
     314    );
    297315}
    298316add_action( 'widgets_init', 'twentytwelve_widgets_init' );
    299317
    300318if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
    301 /**
    302  * Displays navigation to next/previous pages when applicable.
    303  *
    304  * @since Twenty Twelve 1.0
    305  */
    306 function twentytwelve_content_nav( $html_id ) {
    307     global $wp_query;
    308 
    309     if ( $wp_query->max_num_pages > 1 ) : ?>
    310         <nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
    311             <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
    312             <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
    313             <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
    314         </nav><!-- .navigation -->
    315     <?php endif;
    316 }
     319    /**
     320     * Displays navigation to next/previous pages when applicable.
     321     *
     322     * @since Twenty Twelve 1.0
     323     */
     324    function twentytwelve_content_nav( $html_id ) {
     325        global $wp_query;
     326
     327        if ( $wp_query->max_num_pages > 1 ) : ?>
     328            <nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
     329                <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
     330                <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
     331                <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
     332            </nav><!-- .navigation -->
     333        <?php
     334    endif;
     335    }
    317336endif;
    318337
    319338if ( ! function_exists( 'twentytwelve_comment' ) ) :
    320 /**
    321  * Template for comments and pingbacks.
    322  *
    323  * To override this walker in a child theme without modifying the comments template
    324  * simply create your own twentytwelve_comment(), and that function will be used instead.
    325  *
    326  * Used as a callback by wp_list_comments() for displaying the comments.
    327  *
    328  * @since Twenty Twelve 1.0
    329  */
    330 function twentytwelve_comment( $comment, $args, $depth ) {
    331     $GLOBALS['comment'] = $comment;
    332     switch ( $comment->comment_type ) :
    333         case 'pingback' :
    334         case 'trackback' :
    335         // Display trackbacks differently than normal comments.
    336     ?>
    337     <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
     339    /**
     340    * Template for comments and pingbacks.
     341    *
     342    * To override this walker in a child theme without modifying the comments template
     343    * simply create your own twentytwelve_comment(), and that function will be used instead.
     344    *
     345    * Used as a callback by wp_list_comments() for displaying the comments.
     346    *
     347    * @since Twenty Twelve 1.0
     348    */
     349    function twentytwelve_comment( $comment, $args, $depth ) {
     350        $GLOBALS['comment'] = $comment;
     351        switch ( $comment->comment_type ) :
     352            case 'pingback':
     353            case 'trackback':
     354                // Display trackbacks differently than normal comments.
     355        ?>
     356        <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
    338357        <p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
    339358    <?php
    340             break;
    341         default :
    342         // Proceed with normal comments.
    343         global $post;
    344     ?>
    345     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
     359                break;
     360            default:
     361                // Proceed with normal comments.
     362                global $post;
     363        ?>
     364        <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    346365        <article id="comment-<?php comment_ID(); ?>" class="comment">
    347366            <header class="comment-meta comment-author vcard">
    348367                <?php
    349368                    echo get_avatar( $comment, 44 );
    350                     printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
     369                    printf(
     370                        '<cite><b class="fn">%1$s</b> %2$s</cite>',
    351371                        get_comment_author_link(),
    352372                        // If current post author is also comment author, make it known visually.
    353373                        ( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
    354374                    );
    355                     printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
     375                    printf(
     376                        '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
    356377                        esc_url( get_comment_link( $comment->comment_ID ) ),
    357378                        get_comment_time( 'c' ),
     
    359380                        sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
    360381                    );
    361                 ?>
    362             </header><!-- .comment-meta -->
    363 
    364             <?php if ( '0' == $comment->comment_approved ) : ?>
     382                    ?>
     383                </header><!-- .comment-meta -->
     384
     385                <?php if ( '0' == $comment->comment_approved ) : ?>
    365386                <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
    366387            <?php endif; ?>
    367388
    368             <section class="comment-content comment">
     389                <section class="comment-content comment">
    369390                <?php comment_text(); ?>
    370391                <?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
    371             </section><!-- .comment-content -->
    372 
    373             <div class="reply">
    374                 <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    375             </div><!-- .reply -->
    376         </article><!-- #comment-## -->
    377     <?php
    378         break;
    379     endswitch; // end comment_type check
    380 }
     392                </section><!-- .comment-content -->
     393
     394                <div class="reply">
     395                <?php
     396                comment_reply_link(
     397                    array_merge(
     398                        $args, array(
     399                            'reply_text' => __( 'Reply', 'twentytwelve' ),
     400                            'after'      => ' <span>&darr;</span>',
     401                            'depth'      => $depth,
     402                            'max_depth'  => $args['max_depth'],
     403                        )
     404                    )
     405                );
     406?>
     407                </div><!-- .reply -->
     408            </article><!-- #comment-## -->
     409        <?php
     410                break;
     411        endswitch; // end comment_type check
     412    }
    381413endif;
    382414
    383415if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
    384 /**
    385  * Set up post entry meta.
    386  *
    387  * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
    388  *
    389  * Create your own twentytwelve_entry_meta() to override in a child theme.
    390  *
    391  * @since Twenty Twelve 1.0
    392  */
    393 function twentytwelve_entry_meta() {
    394     // Translators: used between list items, there is a space after the comma.
    395     $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
    396 
    397     // Translators: used between list items, there is a space after the comma.
    398     $tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
    399 
    400     $date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
    401         esc_url( get_permalink() ),
    402         esc_attr( get_the_time() ),
    403         esc_attr( get_the_date( 'c' ) ),
    404         esc_html( get_the_date() )
    405     );
    406 
    407     $author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
    408         esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    409         esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
    410         get_the_author()
    411     );
    412 
    413     // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
    414     if ( $tag_list ) {
    415         $utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    416     } elseif ( $categories_list ) {
    417         $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    418     } else {
    419         $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    420     }
    421 
    422     printf(
    423         $utility_text,
    424         $categories_list,
    425         $tag_list,
    426         $date,
    427         $author
    428     );
    429 }
     416    /**
     417     * Set up post entry meta.
     418     *
     419     * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
     420     *
     421     * Create your own twentytwelve_entry_meta() to override in a child theme.
     422     *
     423     * @since Twenty Twelve 1.0
     424     */
     425    function twentytwelve_entry_meta() {
     426        // Translators: used between list items, there is a space after the comma.
     427        $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
     428
     429        // Translators: used between list items, there is a space after the comma.
     430        $tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
     431
     432        $date = sprintf(
     433            '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
     434            esc_url( get_permalink() ),
     435            esc_attr( get_the_time() ),
     436            esc_attr( get_the_date( 'c' ) ),
     437            esc_html( get_the_date() )
     438        );
     439
     440        $author = sprintf(
     441            '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
     442            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
     443            esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
     444            get_the_author()
     445        );
     446
     447        // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
     448        if ( $tag_list ) {
     449            $utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
     450        } elseif ( $categories_list ) {
     451            $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
     452        } else {
     453            $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
     454        }
     455
     456        printf(
     457            $utility_text,
     458            $categories_list,
     459            $tag_list,
     460            $date,
     461            $author
     462        );
     463    }
    430464endif;
    431465
     
    451485    $background_image = get_background_image();
    452486
    453     if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) )
     487    if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) {
    454488        $classes[] = 'full-width';
     489    }
    455490
    456491    if ( is_page_template( 'page-templates/front-page.php' ) ) {
    457492        $classes[] = 'template-front-page';
    458         if ( has_post_thumbnail() )
     493        if ( has_post_thumbnail() ) {
    459494            $classes[] = 'has-post-thumbnail';
    460         if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) )
     495        }
     496        if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) ) {
    461497            $classes[] = 'two-sidebars';
     498        }
    462499    }
    463500
    464501    if ( empty( $background_image ) ) {
    465         if ( empty( $background_color ) )
     502        if ( empty( $background_color ) ) {
    466503            $classes[] = 'custom-background-empty';
    467         elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) )
     504        } elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) {
    468505            $classes[] = 'custom-background-white';
     506        }
    469507    }
    470508
    471509    // Enable custom font class only if the font CSS is queued to load.
    472     if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) )
     510    if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) {
    473511        $classes[] = 'custom-font-enabled';
    474 
    475     if ( ! is_multi_author() )
     512    }
     513
     514    if ( ! is_multi_author() ) {
    476515        $classes[] = 'single-author';
     516    }
    477517
    478518    return $classes;
     
    511551
    512552    if ( isset( $wp_customize->selective_refresh ) ) {
    513         $wp_customize->selective_refresh->add_partial( 'blogname', array(
    514             'selector' => '.site-title > a',
    515             'container_inclusive' => false,
    516             'render_callback' => 'twentytwelve_customize_partial_blogname',
    517         ) );
    518         $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
    519             'selector' => '.site-description',
    520             'container_inclusive' => false,
    521             'render_callback' => 'twentytwelve_customize_partial_blogdescription',
    522         ) );
     553        $wp_customize->selective_refresh->add_partial(
     554            'blogname', array(
     555                'selector'            => '.site-title > a',
     556                'container_inclusive' => false,
     557                'render_callback'     => 'twentytwelve_customize_partial_blogname',
     558            )
     559        );
     560        $wp_customize->selective_refresh->add_partial(
     561            'blogdescription', array(
     562                'selector'            => '.site-description',
     563                'container_inclusive' => false,
     564                'render_callback'     => 'twentytwelve_customize_partial_blogdescription',
     565            )
     566        );
    523567    }
    524568}
Note: See TracChangeset for help on using the changeset viewer.