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-content/themes/twentythirteen/functions.php

    r41756 r42343  
    2929 * @see twentythirteen_content_width() for template-specific adjustments.
    3030 */
    31 if ( ! isset( $content_width ) )
     31if ( ! isset( $content_width ) ) {
    3232    $content_width = 604;
     33}
    3334
    3435/**
     
    4041 * Twenty Thirteen only works in WordPress 3.6 or later.
    4142 */
    42 if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) )
     43if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) ) {
    4344    require get_template_directory() . '/inc/back-compat.php';
     45}
    4446
    4547/**
     
    8284     * and comments to output valid HTML5.
    8385     */
    84     add_theme_support( 'html5', array(
    85         'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
    86     ) );
     86    add_theme_support(
     87        'html5', array(
     88            'search-form',
     89            'comment-form',
     90            'comment-list',
     91            'gallery',
     92            'caption',
     93        )
     94    );
    8795
    8896    /*
     
    9098     * See https://codex.wordpress.org/Post_Formats
    9199     */
    92     add_theme_support( 'post-formats', array(
    93         'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video'
    94     ) );
     100    add_theme_support(
     101        'post-formats', array(
     102            'aside',
     103            'audio',
     104            'chat',
     105            'gallery',
     106            'image',
     107            'link',
     108            'quote',
     109            'status',
     110            'video',
     111        )
     112    );
    95113
    96114    // This theme uses wp_nav_menu() in one location.
     
    140158        $font_families = array();
    141159
    142         if ( 'off' !== $source_sans_pro )
     160        if ( 'off' !== $source_sans_pro ) {
    143161            $font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
    144 
    145         if ( 'off' !== $bitter )
     162        }
     163
     164        if ( 'off' !== $bitter ) {
    146165            $font_families[] = 'Bitter:400,700';
     166        }
    147167
    148168        $query_args = array(
     
    150170            'subset' => urlencode( 'latin,latin-ext' ),
    151171        );
    152         $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
     172        $fonts_url  = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    153173    }
    154174
     
    166186     * sites with threaded comments (when in use).
    167187     */
    168     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
     188    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    169189        wp_enqueue_script( 'comment-reply' );
     190    }
    170191
    171192    // Adds Masonry to handle vertical alignment of footer widgets.
    172     if ( is_active_sidebar( 'sidebar-1' ) )
     193    if ( is_active_sidebar( 'sidebar-1' ) ) {
    173194        wp_enqueue_script( 'jquery-masonry' );
     195    }
    174196
    175197    // Loads JavaScript file with functionality specific to Twenty Thirteen.
     
    231253    global $paged, $page;
    232254
    233     if ( is_feed() )
     255    if ( is_feed() ) {
    234256        return $title;
     257    }
    235258
    236259    // Add the site name.
     
    239262    // Add the site description for the home/front page.
    240263    $site_description = get_bloginfo( 'description', 'display' );
    241     if ( $site_description && ( is_home() || is_front_page() ) )
     264    if ( $site_description && ( is_home() || is_front_page() ) ) {
    242265        $title = "$title $sep $site_description";
     266    }
    243267
    244268    // Add a page number if necessary.
    245     if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() )
     269    if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    246270        $title = "$title $sep " . sprintf( __( 'Page %s', 'twentythirteen' ), max( $paged, $page ) );
     271    }
    247272
    248273    return $title;
     
    256281 */
    257282function twentythirteen_widgets_init() {
    258     register_sidebar( array(
    259         'name'          => __( 'Main Widget Area', 'twentythirteen' ),
    260         'id'            => 'sidebar-1',
    261         'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
    262         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    263         'after_widget'  => '</aside>',
    264         'before_title'  => '<h3 class="widget-title">',
    265         'after_title'   => '</h3>',
    266     ) );
    267 
    268     register_sidebar( array(
    269         'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
    270         'id'            => 'sidebar-2',
    271         'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
    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     ) );
     283    register_sidebar(
     284        array(
     285            'name'          => __( 'Main Widget Area', 'twentythirteen' ),
     286            'id'            => 'sidebar-1',
     287            'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
     288            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     289            'after_widget'  => '</aside>',
     290            'before_title'  => '<h3 class="widget-title">',
     291            'after_title'   => '</h3>',
     292        )
     293    );
     294
     295    register_sidebar(
     296        array(
     297            'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
     298            'id'            => 'sidebar-2',
     299            'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
     300            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     301            'after_widget'  => '</aside>',
     302            'before_title'  => '<h3 class="widget-title">',
     303            'after_title'   => '</h3>',
     304        )
     305    );
    277306}
    278307add_action( 'widgets_init', 'twentythirteen_widgets_init' );
    279308
    280309if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
    281 /**
    282  * Display navigation to next/previous set of posts when applicable.
    283  *
    284  * @since Twenty Thirteen 1.0
    285  */
    286 function twentythirteen_paging_nav() {
    287     global $wp_query;
    288 
    289     // Don't print empty markup if there's only one page.
    290     if ( $wp_query->max_num_pages < 2 )
    291         return;
    292     ?>
    293     <nav class="navigation paging-navigation" role="navigation">
     310    /**
     311     * Display navigation to next/previous set of posts when applicable.
     312     *
     313     * @since Twenty Thirteen 1.0
     314     */
     315    function twentythirteen_paging_nav() {
     316        global $wp_query;
     317
     318        // Don't print empty markup if there's only one page.
     319        if ( $wp_query->max_num_pages < 2 ) {
     320            return;
     321        }
     322        ?>
     323        <nav class="navigation paging-navigation" role="navigation">
    294324        <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
    295325        <div class="nav-links">
     
    306336    </nav><!-- .navigation -->
    307337    <?php
    308 }
     338    }
    309339endif;
    310340
    311341if ( ! function_exists( 'twentythirteen_post_nav' ) ) :
    312 /**
    313  * Display navigation to next/previous post when applicable.
    314  *
    315  * @since Twenty Thirteen 1.0
    316  */
    317 function twentythirteen_post_nav() {
    318     global $post;
    319 
    320     // Don't print empty markup if there's nowhere to navigate.
    321     $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
    322     $next     = get_adjacent_post( false, '', false );
    323 
    324     if ( ! $next && ! $previous )
    325         return;
    326     ?>
    327     <nav class="navigation post-navigation" role="navigation">
     342    /**
     343     * Display navigation to next/previous post when applicable.
     344     *
     345     * @since Twenty Thirteen 1.0
     346     */
     347    function twentythirteen_post_nav() {
     348        global $post;
     349
     350        // Don't print empty markup if there's nowhere to navigate.
     351        $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
     352        $next     = get_adjacent_post( false, '', false );
     353
     354        if ( ! $next && ! $previous ) {
     355            return;
     356        }
     357        ?>
     358        <nav class="navigation post-navigation" role="navigation">
    328359        <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentythirteen' ); ?></h1>
    329360        <div class="nav-links">
     
    335366    </nav><!-- .navigation -->
    336367    <?php
    337 }
     368    }
    338369endif;
    339370
    340371if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
    341 /**
    342  * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
    343  *
    344  * Create your own twentythirteen_entry_meta() to override in a child theme.
    345  *
    346  * @since Twenty Thirteen 1.0
    347  */
    348 function twentythirteen_entry_meta() {
    349     if ( is_sticky() && is_home() && ! is_paged() )
    350         echo '<span class="featured-post">' . esc_html__( 'Sticky', 'twentythirteen' ) . '</span>';
    351 
    352     if ( ! has_post_format( 'link' ) && 'post' == get_post_type() )
    353         twentythirteen_entry_date();
    354 
    355     // Translators: used between list items, there is a space after the comma.
    356     $categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
    357     if ( $categories_list ) {
    358         echo '<span class="categories-links">' . $categories_list . '</span>';
    359     }
    360 
    361     // Translators: used between list items, there is a space after the comma.
    362     $tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
    363     if ( $tag_list ) {
    364         echo '<span class="tags-links">' . $tag_list . '</span>';
    365     }
    366 
    367     // Post author
    368     if ( 'post' == get_post_type() ) {
    369         printf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
    370             esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    371             esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ),
    372             get_the_author()
     372    /**
     373     * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
     374     *
     375     * Create your own twentythirteen_entry_meta() to override in a child theme.
     376     *
     377     * @since Twenty Thirteen 1.0
     378     */
     379    function twentythirteen_entry_meta() {
     380        if ( is_sticky() && is_home() && ! is_paged() ) {
     381            echo '<span class="featured-post">' . esc_html__( 'Sticky', 'twentythirteen' ) . '</span>';
     382        }
     383
     384        if ( ! has_post_format( 'link' ) && 'post' == get_post_type() ) {
     385            twentythirteen_entry_date();
     386        }
     387
     388        // Translators: used between list items, there is a space after the comma.
     389        $categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
     390        if ( $categories_list ) {
     391            echo '<span class="categories-links">' . $categories_list . '</span>';
     392        }
     393
     394        // Translators: used between list items, there is a space after the comma.
     395        $tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
     396        if ( $tag_list ) {
     397            echo '<span class="tags-links">' . $tag_list . '</span>';
     398        }
     399
     400        // Post author
     401        if ( 'post' == get_post_type() ) {
     402            printf(
     403                '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
     404                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
     405                esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ),
     406                get_the_author()
     407            );
     408        }
     409    }
     410endif;
     411
     412if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
     413    /**
     414     * Print HTML with date information for current post.
     415     *
     416     * Create your own twentythirteen_entry_date() to override in a child theme.
     417     *
     418     * @since Twenty Thirteen 1.0
     419     *
     420     * @param boolean $echo (optional) Whether to echo the date. Default true.
     421     * @return string The HTML-formatted post date.
     422     */
     423    function twentythirteen_entry_date( $echo = true ) {
     424        if ( has_post_format( array( 'chat', 'status' ) ) ) {
     425            $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
     426        } else {
     427            $format_prefix = '%2$s';
     428        }
     429
     430        $date = sprintf(
     431            '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
     432            esc_url( get_permalink() ),
     433            esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
     434            esc_attr( get_the_date( 'c' ) ),
     435            esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
    373436        );
    374     }
    375 }
     437
     438        if ( $echo ) {
     439            echo $date;
     440        }
     441
     442        return $date;
     443    }
    376444endif;
    377445
    378 if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
    379 /**
    380  * Print HTML with date information for current post.
    381  *
    382  * Create your own twentythirteen_entry_date() to override in a child theme.
    383  *
    384  * @since Twenty Thirteen 1.0
    385  *
    386  * @param boolean $echo (optional) Whether to echo the date. Default true.
    387  * @return string The HTML-formatted post date.
    388  */
    389 function twentythirteen_entry_date( $echo = true ) {
    390     if ( has_post_format( array( 'chat', 'status' ) ) )
    391         $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
    392     else
    393         $format_prefix = '%2$s';
    394 
    395     $date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
    396         esc_url( get_permalink() ),
    397         esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
    398         esc_attr( get_the_date( 'c' ) ),
    399         esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
    400     );
    401 
    402     if ( $echo )
    403         echo $date;
    404 
    405     return $date;
    406 }
    407 endif;
    408 
    409446if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) :
    410 /**
    411  * Print the attached image with a link to the next attached image.
    412  *
    413  * @since Twenty Thirteen 1.0
    414  */
    415 function twentythirteen_the_attached_image() {
    416447    /**
    417      * Filter the image attachment size to use.
    418      *
    419      * @since Twenty thirteen 1.0
    420      *
    421      * @param array $size {
    422      *     @type int The attachment height in pixels.
    423      *     @type int The attachment width in pixels.
    424      * }
    425      */
    426     $attachment_size     = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) );
    427     $next_attachment_url = wp_get_attachment_url();
    428     $post                = get_post();
    429 
    430     /*
    431      * Grab the IDs of all the image attachments in a gallery so we can get the URL
    432      * of the next adjacent image in a gallery, or the first image (if we're
    433      * looking at the last image in a gallery), or, in a gallery of one, just the
    434      * link to that image file.
    435      */
    436     $attachment_ids = get_posts( array(
    437         'post_parent'    => $post->post_parent,
    438         'fields'         => 'ids',
    439         'numberposts'    => -1,
    440         'post_status'    => 'inherit',
    441         'post_type'      => 'attachment',
    442         'post_mime_type' => 'image',
    443         'order'          => 'ASC',
    444         'orderby'        => 'menu_order ID',
    445     ) );
    446 
    447     // If there is more than 1 attachment in a gallery...
    448     if ( count( $attachment_ids ) > 1 ) {
    449         foreach ( $attachment_ids as $idx => $attachment_id ) {
    450             if ( $attachment_id == $post->ID ) {
    451                 $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
    452                 break;
     448     * Print the attached image with a link to the next attached image.
     449     *
     450     * @since Twenty Thirteen 1.0
     451     */
     452    function twentythirteen_the_attached_image() {
     453        /**
     454         * Filter the image attachment size to use.
     455         *
     456         * @since Twenty thirteen 1.0
     457         *
     458         * @param array $size {
     459         *     @type int The attachment height in pixels.
     460         *     @type int The attachment width in pixels.
     461         * }
     462         */
     463        $attachment_size     = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) );
     464        $next_attachment_url = wp_get_attachment_url();
     465        $post                = get_post();
     466
     467        /*
     468         * Grab the IDs of all the image attachments in a gallery so we can get the URL
     469         * of the next adjacent image in a gallery, or the first image (if we're
     470         * looking at the last image in a gallery), or, in a gallery of one, just the
     471         * link to that image file.
     472         */
     473        $attachment_ids = get_posts(
     474            array(
     475                'post_parent'    => $post->post_parent,
     476                'fields'         => 'ids',
     477                'numberposts'    => -1,
     478                'post_status'    => 'inherit',
     479                'post_type'      => 'attachment',
     480                'post_mime_type' => 'image',
     481                'order'          => 'ASC',
     482                'orderby'        => 'menu_order ID',
     483            )
     484        );
     485
     486        // If there is more than 1 attachment in a gallery...
     487        if ( count( $attachment_ids ) > 1 ) {
     488            foreach ( $attachment_ids as $idx => $attachment_id ) {
     489                if ( $attachment_id == $post->ID ) {
     490                    $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
     491                    break;
     492                }
    453493            }
    454         }
    455 
    456         // get the URL of the next image attachment...
    457         if ( $next_id )
    458             $next_attachment_url = get_attachment_link( $next_id );
    459 
    460         // or get the URL of the first image attachment.
    461         else
    462             $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
    463     }
    464 
    465     printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
    466         esc_url( $next_attachment_url ),
    467         the_title_attribute( array( 'echo' => false ) ),
    468         wp_get_attachment_image( $post->ID, $attachment_size )
    469     );
    470 }
     494
     495            // get the URL of the next image attachment...
     496            if ( $next_id ) {
     497                $next_attachment_url = get_attachment_link( $next_id );
     498            } // or get the URL of the first image attachment.
     499            else {
     500                $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
     501            }
     502        }
     503
     504        printf(
     505            '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
     506            esc_url( $next_attachment_url ),
     507            the_title_attribute( array( 'echo' => false ) ),
     508            wp_get_attachment_image( $post->ID, $attachment_size )
     509        );
     510    }
    471511endif;
    472512
     
    491531
    492532if ( ! function_exists( 'twentythirteen_excerpt_more' ) && ! is_admin() ) :
    493 /**
    494  * Replaces "[...]" (appended to automatically generated excerpts) with ...
    495  * and a Continue reading link.
    496  *
    497  * @since Twenty Thirteen 1.4
    498  *
    499  * @param string $more Default Read More excerpt link.
    500  * @return string Filtered Read More excerpt link.
    501  */
    502 function twentythirteen_excerpt_more( $more ) {
    503     $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
    504         esc_url( get_permalink( get_the_ID() ) ),
     533    /**
     534     * Replaces "[...]" (appended to automatically generated excerpts) with ...
     535     * and a Continue reading link.
     536     *
     537     * @since Twenty Thirteen 1.4
     538     *
     539     * @param string $more Default Read More excerpt link.
     540     * @return string Filtered Read More excerpt link.
     541     */
     542    function twentythirteen_excerpt_more( $more ) {
     543        $link = sprintf(
     544            '<a href="%1$s" class="more-link">%2$s</a>',
     545            esc_url( get_permalink( get_the_ID() ) ),
    505546            /* translators: %s: Name of current post */
    506547            sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentythirteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
    507548        );
    508     return ' &hellip; ' . $link;
    509 }
    510 add_filter( 'excerpt_more', 'twentythirteen_excerpt_more' );
     549        return ' &hellip; ' . $link;
     550    }
     551    add_filter( 'excerpt_more', 'twentythirteen_excerpt_more' );
    511552endif;
    512553
     
    525566 */
    526567function twentythirteen_body_class( $classes ) {
    527     if ( ! is_multi_author() )
     568    if ( ! is_multi_author() ) {
    528569        $classes[] = 'single-author';
    529 
    530     if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() )
     570    }
     571
     572    if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() ) {
    531573        $classes[] = 'sidebar';
    532 
    533     if ( ! get_option( 'show_avatars' ) )
     574    }
     575
     576    if ( ! get_option( 'show_avatars' ) ) {
    534577        $classes[] = 'no-avatars';
     578    }
    535579
    536580    return $classes;
     
    546590    global $content_width;
    547591
    548     if ( is_attachment() )
     592    if ( is_attachment() ) {
    549593        $content_width = 724;
    550     elseif ( has_post_format( 'audio' ) )
     594    } elseif ( has_post_format( 'audio' ) ) {
    551595        $content_width = 484;
     596    }
    552597}
    553598add_action( 'template_redirect', 'twentythirteen_content_width' );
     
    566611
    567612    if ( isset( $wp_customize->selective_refresh ) ) {
    568         $wp_customize->selective_refresh->add_partial( 'blogname', array(
    569             'selector' => '.site-title',
    570             'container_inclusive' => false,
    571             'render_callback' => 'twentythirteen_customize_partial_blogname',
    572         ) );
    573         $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
    574             'selector' => '.site-description',
    575             'container_inclusive' => false,
    576             'render_callback' => 'twentythirteen_customize_partial_blogdescription',
    577         ) );
     613        $wp_customize->selective_refresh->add_partial(
     614            'blogname', array(
     615                'selector'            => '.site-title',
     616                'container_inclusive' => false,
     617                'render_callback'     => 'twentythirteen_customize_partial_blogname',
     618            )
     619        );
     620        $wp_customize->selective_refresh->add_partial(
     621            'blogdescription', array(
     622                'selector'            => '.site-description',
     623                'container_inclusive' => false,
     624                'render_callback'     => 'twentythirteen_customize_partial_blogdescription',
     625            )
     626        );
    578627    }
    579628}
Note: See TracChangeset for help on using the changeset viewer.