Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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/twentyfifteen/inc/template-tags.php

    r41756 r42343  
    1111
    1212if ( ! function_exists( 'twentyfifteen_comment_nav' ) ) :
    13 /**
    14  * Display navigation to next/previous comments when applicable.
    15  *
    16  * @since Twenty Fifteen 1.0
    17  */
    18 function twentyfifteen_comment_nav() {
    19         // Are there comments to navigate through?
    20         if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
    21         ?>
    22         <nav class="navigation comment-navigation" role="navigation">
     13        /**
     14        * Display navigation to next/previous comments when applicable.
     15        *
     16        * @since Twenty Fifteen 1.0
     17        */
     18        function twentyfifteen_comment_nav() {
     19                // Are there comments to navigate through?
     20                if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
     21                ?>
     22                <nav class="navigation comment-navigation" role="navigation">
    2323                <h2 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfifteen' ); ?></h2>
    2424                <div class="nav-links">
    2525                        <?php
    26                                 if ( $prev_link = get_previous_comments_link( __( 'Older Comments', 'twentyfifteen' ) ) ) :
    27                                         printf( '<div class="nav-previous">%s</div>', $prev_link );
     26                        if ( $prev_link = get_previous_comments_link( __( 'Older Comments', 'twentyfifteen' ) ) ) :
     27                                printf( '<div class="nav-previous">%s</div>', $prev_link );
    2828                                endif;
    2929
    30                                 if ( $next_link = get_next_comments_link( __( 'Newer Comments', 'twentyfifteen' ) ) ) :
    31                                         printf( '<div class="nav-next">%s</div>', $next_link );
     30                        if ( $next_link = get_next_comments_link( __( 'Newer Comments', 'twentyfifteen' ) ) ) :
     31                                printf( '<div class="nav-next">%s</div>', $next_link );
    3232                                endif;
    3333                        ?>
    34                 </div><!-- .nav-links -->
    35         </nav><!-- .comment-navigation -->
    36         <?php
    37         endif;
    38 }
     34                        </div><!-- .nav-links -->
     35                </nav><!-- .comment-navigation -->
     36                <?php
     37                endif;
     38        }
    3939endif;
    4040
    4141if ( ! function_exists( 'twentyfifteen_entry_meta' ) ) :
    42 /**
    43  * Prints HTML with meta information for the categories, tags.
    44  *
    45  * @since Twenty Fifteen 1.0
    46  */
    47 function twentyfifteen_entry_meta() {
    48         if ( is_sticky() && is_home() && ! is_paged() ) {
    49                 printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'twentyfifteen' ) );
    50         }
    51 
    52         $format = get_post_format();
    53         if ( current_theme_supports( 'post-formats', $format ) ) {
    54                 printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
    55                         sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ),
    56                         esc_url( get_post_format_link( $format ) ),
    57                         get_post_format_string( $format )
    58                 );
    59         }
    60 
    61         if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
    62                 $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    63 
    64                 if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    65                         $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    66                 }
    67 
    68                 $time_string = sprintf( $time_string,
    69                         esc_attr( get_the_date( 'c' ) ),
    70                         get_the_date(),
    71                         esc_attr( get_the_modified_date( 'c' ) ),
    72                         get_the_modified_date()
    73                 );
    74 
    75                 printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>',
    76                         _x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ),
    77                         esc_url( get_permalink() ),
    78                         $time_string
    79                 );
    80         }
    81 
    82         if ( 'post' == get_post_type() ) {
    83                 if ( is_singular() || is_multi_author() ) {
    84                         printf( '<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>',
    85                                 _x( 'Author', 'Used before post author name.', 'twentyfifteen' ),
    86                                 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    87                                 get_the_author()
    88                         );
    89                 }
    90 
    91                 $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
    92                 if ( $categories_list && twentyfifteen_categorized_blog() ) {
    93                         printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
    94                                 _x( 'Categories', 'Used before category names.', 'twentyfifteen' ),
    95                                 $categories_list
    96                         );
    97                 }
    98 
    99                 $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
    100                 if ( $tags_list && ! is_wp_error( $tags_list ) ) {
    101                         printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
    102                                 _x( 'Tags', 'Used before tag names.', 'twentyfifteen' ),
    103                                 $tags_list
    104                         );
    105                 }
    106         }
    107 
    108         if ( is_attachment() && wp_attachment_is_image() ) {
    109                 // Retrieve attachment metadata.
    110                 $metadata = wp_get_attachment_metadata();
    111 
    112                 printf( '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s &times; %4$s</a></span>',
    113                         _x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ),
    114                         esc_url( wp_get_attachment_url() ),
    115                         $metadata['width'],
    116                         $metadata['height']
    117                 );
    118         }
    119 
    120         if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    121                 echo '<span class="comments-link">';
    122                 /* translators: %s: post title */
    123                 comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentyfifteen' ), get_the_title() ) );
    124                 echo '</span>';
    125         }
    126 }
     42        /**
     43         * Prints HTML with meta information for the categories, tags.
     44         *
     45         * @since Twenty Fifteen 1.0
     46         */
     47        function twentyfifteen_entry_meta() {
     48                if ( is_sticky() && is_home() && ! is_paged() ) {
     49                        printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'twentyfifteen' ) );
     50                }
     51
     52                $format = get_post_format();
     53                if ( current_theme_supports( 'post-formats', $format ) ) {
     54                        printf(
     55                                '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
     56                                sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ),
     57                                esc_url( get_post_format_link( $format ) ),
     58                                get_post_format_string( $format )
     59                        );
     60                }
     61
     62                if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
     63                        $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
     64
     65                        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
     66                                $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
     67                        }
     68
     69                        $time_string = sprintf(
     70                                $time_string,
     71                                esc_attr( get_the_date( 'c' ) ),
     72                                get_the_date(),
     73                                esc_attr( get_the_modified_date( 'c' ) ),
     74                                get_the_modified_date()
     75                        );
     76
     77                        printf(
     78                                '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>',
     79                                _x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ),
     80                                esc_url( get_permalink() ),
     81                                $time_string
     82                        );
     83                }
     84
     85                if ( 'post' == get_post_type() ) {
     86                        if ( is_singular() || is_multi_author() ) {
     87                                printf(
     88                                        '<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>',
     89                                        _x( 'Author', 'Used before post author name.', 'twentyfifteen' ),
     90                                        esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
     91                                        get_the_author()
     92                                );
     93                        }
     94
     95                        $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
     96                        if ( $categories_list && twentyfifteen_categorized_blog() ) {
     97                                printf(
     98                                        '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
     99                                        _x( 'Categories', 'Used before category names.', 'twentyfifteen' ),
     100                                        $categories_list
     101                                );
     102                        }
     103
     104                        $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
     105                        if ( $tags_list && ! is_wp_error( $tags_list ) ) {
     106                                printf(
     107                                        '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
     108                                        _x( 'Tags', 'Used before tag names.', 'twentyfifteen' ),
     109                                        $tags_list
     110                                );
     111                        }
     112                }
     113
     114                if ( is_attachment() && wp_attachment_is_image() ) {
     115                        // Retrieve attachment metadata.
     116                        $metadata = wp_get_attachment_metadata();
     117
     118                        printf(
     119                                '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s &times; %4$s</a></span>',
     120                                _x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ),
     121                                esc_url( wp_get_attachment_url() ),
     122                                $metadata['width'],
     123                                $metadata['height']
     124                        );
     125                }
     126
     127                if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
     128                        echo '<span class="comments-link">';
     129                        /* translators: %s: post title */
     130                        comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentyfifteen' ), get_the_title() ) );
     131                        echo '</span>';
     132                }
     133        }
    127134endif;
    128135
    … …  
    137144        if ( false === ( $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ) ) ) {
    138145                // Create an array of all the categories that are attached to posts.
    139                 $all_the_cool_cats = get_categories( array(
    140                         'fields'     => 'ids',
    141                         'hide_empty' => 1,
    142 
    143                         // We only need to know if there is more than one category.
    144                         'number'     => 2,
    145                 ) );
     146                $all_the_cool_cats = get_categories(
     147                        array(
     148                                'fields'     => 'ids',
     149                                'hide_empty' => 1,
     150
     151                                // We only need to know if there is more than one category.
     152                                'number'     => 2,
     153                        )
     154                );
    146155
    147156                // Count the number of categories that are attached to the posts.
    … …  
    170179}
    171180add_action( 'edit_category', 'twentyfifteen_category_transient_flusher' );
    172 add_action( 'save_post',     'twentyfifteen_category_transient_flusher' );
     181add_action( 'save_post', 'twentyfifteen_category_transient_flusher' );
    173182
    174183if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) :
    175 /**
    176  * Display an optional post thumbnail.
    177  *
    178  * Wraps the post thumbnail in an anchor element on index views, or a div
    179  * element when on single views.
    180  *
    181  * @since Twenty Fifteen 1.0
    182  */
    183 function twentyfifteen_post_thumbnail() {
    184         if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
    185                 return;
    186         }
    187 
    188         if ( is_singular() ) :
    189         ?>
    190 
    191         <div class="post-thumbnail">
     184        /**
     185        * Display an optional post thumbnail.
     186        *
     187        * Wraps the post thumbnail in an anchor element on index views, or a div
     188        * element when on single views.
     189        *
     190        * @since Twenty Fifteen 1.0
     191        */
     192        function twentyfifteen_post_thumbnail() {
     193                if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
     194                        return;
     195                }
     196
     197                if ( is_singular() ) :
     198                ?>
     199
     200                <div class="post-thumbnail">
    192201                <?php the_post_thumbnail(); ?>
    193202        </div><!-- .post-thumbnail -->
    … …  
    201210        </a>
    202211
    203         <?php endif; // End is_singular()
    204 }
     212        <?php
     213        endif; // End is_singular()
     214        }
    205215endif;
    206216
    207217if ( ! function_exists( 'twentyfifteen_get_link_url' ) ) :
    208 /**
    209  * Return the post URL.
    210  *
    211  * Falls back to the post permalink if no URL is found in the post.
    212  *
    213  * @since Twenty Fifteen 1.0
    214  *
    215  * @see get_url_in_content()
    216  *
    217  * @return string The Link format URL.
    218  */
    219 function twentyfifteen_get_link_url() {
    220         $has_url = get_url_in_content( get_the_content() );
    221 
    222         return $has_url ? $has_url : apply_filters( 'the_permalink', get_permalink() );
    223 }
     218        /**
     219        * Return the post URL.
     220        *
     221        * Falls back to the post permalink if no URL is found in the post.
     222        *
     223        * @since Twenty Fifteen 1.0
     224        *
     225        * @see get_url_in_content()
     226        *
     227        * @return string The Link format URL.
     228        */
     229        function twentyfifteen_get_link_url() {
     230                $has_url = get_url_in_content( get_the_content() );
     231
     232                return $has_url ? $has_url : apply_filters( 'the_permalink', get_permalink() );
     233        }
    224234endif;
    225235
    226236if ( ! function_exists( 'twentyfifteen_excerpt_more' ) && ! is_admin() ) :
    227 /**
    228  * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
    229  *
    230  * @since Twenty Fifteen 1.0
    231  *
    232  * @return string 'Continue reading' link prepended with an ellipsis.
    233  */
    234 function twentyfifteen_excerpt_more( $more ) {
    235         $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
    236                 esc_url( get_permalink( get_the_ID() ) ),
    237                 /* translators: %s: Name of current post */
    238                 sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
     237        /**
     238         * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
     239         *
     240         * @since Twenty Fifteen 1.0
     241         *
     242         * @return string 'Continue reading' link prepended with an ellipsis.
     243         */
     244        function twentyfifteen_excerpt_more( $more ) {
     245                $link = sprintf(
     246                        '<a href="%1$s" class="more-link">%2$s</a>',
     247                        esc_url( get_permalink( get_the_ID() ) ),
     248                        /* translators: %s: Name of current post */
     249                        sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
    239250                );
    240         return ' &hellip; ' . $link;
    241 }
    242 add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
     251                return ' &hellip; ' . $link;
     252        }
     253        add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
    243254endif;
    244255
    245256if ( ! function_exists( 'twentyfifteen_the_custom_logo' ) ) :
    246 /**
    247  * Displays the optional custom logo.
    248  *
    249  * Does nothing if the custom logo is not available.
    250  *
    251  * @since Twenty Fifteen 1.5
    252  */
    253 function twentyfifteen_the_custom_logo() {
    254         if ( function_exists( 'the_custom_logo' ) ) {
    255                 the_custom_logo();
    256         }
    257 }
    258 endif;
     257        /**
     258        * Displays the optional custom logo.
     259        *
     260        * Does nothing if the custom logo is not available.
     261        *
     262        * @since Twenty Fifteen 1.5
     263        */
     264        function twentyfifteen_the_custom_logo() {
     265                if ( function_exists( 'the_custom_logo' ) ) {
     266                        the_custom_logo();
     267                }
     268        }
     269endif;
Note: See TracChangeset for help on using the changeset viewer.