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/twentyfourteen/inc/template-tags.php

    r40023 r42343  
    99
    1010if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) :
    11 /**
    12  * Display navigation to next/previous set of posts when applicable.
    13  *
    14  * @since Twenty Fourteen 1.0
    15  *
    16  * @global WP_Query   $wp_query   WordPress Query object.
    17  * @global WP_Rewrite $wp_rewrite WordPress Rewrite object.
    18  */
    19 function twentyfourteen_paging_nav() {
    20     global $wp_query, $wp_rewrite;
    21 
    22     // Don't print empty markup if there's only one page.
    23     if ( $wp_query->max_num_pages < 2 ) {
    24         return;
    25     }
    26 
    27     $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
    28     $pagenum_link = html_entity_decode( get_pagenum_link() );
    29     $query_args   = array();
    30     $url_parts    = explode( '?', $pagenum_link );
    31 
    32     if ( isset( $url_parts[1] ) ) {
    33         wp_parse_str( $url_parts[1], $query_args );
    34     }
    35 
    36     $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
    37     $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
    38 
    39     $format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
    40     $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
    41 
    42     // Set up paginated links.
    43     $links = paginate_links( array(
    44         'base'     => $pagenum_link,
    45         'format'   => $format,
    46         'total'    => $wp_query->max_num_pages,
    47         'current'  => $paged,
    48         'mid_size' => 1,
    49         'add_args' => array_map( 'urlencode', $query_args ),
    50         'prev_text' => __( '&larr; Previous', 'twentyfourteen' ),
    51         'next_text' => __( 'Next &rarr;', 'twentyfourteen' ),
    52     ) );
    53 
    54     if ( $links ) :
    55 
    56     ?>
    57     <nav class="navigation paging-navigation" role="navigation">
     11    /**
     12     * Display navigation to next/previous set of posts when applicable.
     13     *
     14     * @since Twenty Fourteen 1.0
     15     *
     16     * @global WP_Query   $wp_query   WordPress Query object.
     17     * @global WP_Rewrite $wp_rewrite WordPress Rewrite object.
     18     */
     19    function twentyfourteen_paging_nav() {
     20        global $wp_query, $wp_rewrite;
     21
     22        // Don't print empty markup if there's only one page.
     23        if ( $wp_query->max_num_pages < 2 ) {
     24            return;
     25        }
     26
     27        $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
     28        $pagenum_link = html_entity_decode( get_pagenum_link() );
     29        $query_args   = array();
     30        $url_parts    = explode( '?', $pagenum_link );
     31
     32        if ( isset( $url_parts[1] ) ) {
     33            wp_parse_str( $url_parts[1], $query_args );
     34        }
     35
     36        $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
     37        $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
     38
     39        $format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
     40        $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
     41
     42        // Set up paginated links.
     43        $links = paginate_links(
     44            array(
     45                'base'      => $pagenum_link,
     46                'format'    => $format,
     47                'total'     => $wp_query->max_num_pages,
     48                'current'   => $paged,
     49                'mid_size'  => 1,
     50                'add_args'  => array_map( 'urlencode', $query_args ),
     51                'prev_text' => __( '&larr; Previous', 'twentyfourteen' ),
     52                'next_text' => __( 'Next &rarr;', 'twentyfourteen' ),
     53            )
     54        );
     55
     56        if ( $links ) :
     57
     58        ?>
     59        <nav class="navigation paging-navigation" role="navigation">
    5860        <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1>
    5961        <div class="pagination loop-pagination">
     
    6365    <?php
    6466    endif;
    65 }
     67    }
    6668endif;
    6769
    6870if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
    69 /**
    70  * Display navigation to next/previous post when applicable.
    71  *
    72  * @since Twenty Fourteen 1.0
    73  */
    74 function twentyfourteen_post_nav() {
    75     // Don't print empty markup if there's nowhere to navigate.
    76     $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
    77     $next     = get_adjacent_post( false, '', false );
    78 
    79     if ( ! $next && ! $previous ) {
    80         return;
    81     }
    82 
    83     ?>
    84     <nav class="navigation post-navigation" role="navigation">
     71    /**
     72    * Display navigation to next/previous post when applicable.
     73    *
     74    * @since Twenty Fourteen 1.0
     75    */
     76    function twentyfourteen_post_nav() {
     77        // Don't print empty markup if there's nowhere to navigate.
     78        $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
     79        $next     = get_adjacent_post( false, '', false );
     80
     81        if ( ! $next && ! $previous ) {
     82            return;
     83        }
     84
     85        ?>
     86        <nav class="navigation post-navigation" role="navigation">
    8587        <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
    8688        <div class="nav-links">
     
    8890            if ( is_attachment() ) :
    8991                previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
    90             else :
    91                 previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
    92                 next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
    93             endif;
    94             ?>
    95         </div><!-- .nav-links -->
    96     </nav><!-- .navigation -->
    97     <?php
    98 }
     92                else :
     93                    previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
     94                    next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
     95                endif;
     96                ?>
     97            </div><!-- .nav-links -->
     98        </nav><!-- .navigation -->
     99        <?php
     100    }
    99101endif;
    100102
    101103if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
    102 /**
    103  * Print HTML with meta information for the current post-date/time and author.
    104  *
    105  * @since Twenty Fourteen 1.0
    106  */
    107 function twentyfourteen_posted_on() {
    108     if ( is_sticky() && is_home() && ! is_paged() ) {
    109         echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
    110     }
    111 
    112     // Set up and print post meta information.
    113     printf( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
    114         esc_url( get_permalink() ),
    115         esc_attr( get_the_date( 'c' ) ),
    116         esc_html( get_the_date() ),
    117         esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    118         get_the_author()
    119     );
    120 }
     104    /**
     105     * Print HTML with meta information for the current post-date/time and author.
     106     *
     107     * @since Twenty Fourteen 1.0
     108     */
     109    function twentyfourteen_posted_on() {
     110        if ( is_sticky() && is_home() && ! is_paged() ) {
     111            echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
     112        }
     113
     114        // Set up and print post meta information.
     115        printf(
     116            '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
     117            esc_url( get_permalink() ),
     118            esc_attr( get_the_date( 'c' ) ),
     119            esc_html( get_the_date() ),
     120            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
     121            get_the_author()
     122        );
     123    }
    121124endif;
    122125
     
    131134    if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) {
    132135        // Create an array of all the categories that are attached to posts
    133         $all_the_cool_cats = get_categories( array(
    134             'hide_empty' => 1,
    135         ) );
     136        $all_the_cool_cats = get_categories(
     137            array(
     138                'hide_empty' => 1,
     139            )
     140        );
    136141
    137142        // Count the number of categories that are attached to the posts
     
    160165}
    161166add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
    162 add_action( 'save_post',     'twentyfourteen_category_transient_flusher' );
     167add_action( 'save_post', 'twentyfourteen_category_transient_flusher' );
    163168
    164169if ( ! function_exists( 'twentyfourteen_post_thumbnail' ) ) :
    165 /**
    166  * Display an optional post thumbnail.
    167  *
    168  * Wraps the post thumbnail in an anchor element on index
    169  * views, or a div element when on single views.
    170  *
    171  * @since Twenty Fourteen 1.0
    172  * @since Twenty Fourteen 1.4 Was made 'pluggable', or overridable.
    173  */
    174 function twentyfourteen_post_thumbnail() {
    175     if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
    176         return;
    177     }
    178 
    179     if ( is_singular() ) :
    180     ?>
    181 
    182     <div class="post-thumbnail">
    183     <?php
     170    /**
     171    * Display an optional post thumbnail.
     172    *
     173    * Wraps the post thumbnail in an anchor element on index
     174    * views, or a div element when on single views.
     175    *
     176    * @since Twenty Fourteen 1.0
     177    * @since Twenty Fourteen 1.4 Was made 'pluggable', or overridable.
     178    */
     179    function twentyfourteen_post_thumbnail() {
     180        if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
     181            return;
     182        }
     183
     184        if ( is_singular() ) :
     185        ?>
     186
     187        <div class="post-thumbnail">
     188        <?php
    184189        if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
    185190            the_post_thumbnail( 'twentyfourteen-full-width' );
     
    187192            the_post_thumbnail();
    188193        }
    189     ?>
    190     </div>
    191 
    192     <?php else : ?>
     194        ?>
     195        </div>
     196
     197        <?php else : ?>
    193198
    194199    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
    195200    <?php
    196         if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
    197             the_post_thumbnail( 'twentyfourteen-full-width' );
    198         } else {
    199             the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
    200         }
     201    if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
     202        the_post_thumbnail( 'twentyfourteen-full-width' );
     203    } else {
     204        the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
     205    }
    201206    ?>
    202207    </a>
    203208
    204     <?php endif; // End is_singular()
    205 }
     209    <?php
     210    endif; // End is_singular()
     211    }
    206212endif;
    207213
    208214if ( ! function_exists( 'twentyfourteen_excerpt_more' ) && ! is_admin() ) :
    209 /**
    210  * Replaces "[...]" (appended to automatically generated excerpts) with ...
    211  * and a Continue reading link.
    212  *
    213  * @since Twenty Fourteen 1.3
    214  *
    215  * @param string $more Default Read More excerpt link.
    216  * @return string Filtered Read More excerpt link.
    217  */
    218 function twentyfourteen_excerpt_more( $more ) {
    219     $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
    220         esc_url( get_permalink( get_the_ID() ) ),
     215    /**
     216     * Replaces "[...]" (appended to automatically generated excerpts) with ...
     217     * and a Continue reading link.
     218     *
     219     * @since Twenty Fourteen 1.3
     220     *
     221     * @param string $more Default Read More excerpt link.
     222     * @return string Filtered Read More excerpt link.
     223     */
     224    function twentyfourteen_excerpt_more( $more ) {
     225        $link = sprintf(
     226            '<a href="%1$s" class="more-link">%2$s</a>',
     227            esc_url( get_permalink( get_the_ID() ) ),
    221228            /* translators: %s: Name of current post */
    222229            sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
    223230        );
    224     return ' &hellip; ' . $link;
    225 }
    226 add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' );
    227 endif;
     231        return ' &hellip; ' . $link;
     232    }
     233    add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' );
     234endif;
Note: See TracChangeset for help on using the changeset viewer.