Making WordPress.org


Ignore:
Timestamp:
12/15/2017 12:13:33 AM (7 years ago)
Author:
obenland
Message:

Main: Conform to WPCS.

See #2861.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg/inc/template-tags.php

    r6149 r6277  
    99
    1010if ( ! function_exists( __NAMESPACE__ . '\entry_meta' ) ) :
    11 /**
    12  * Prints HTML with meta information for the categories, tags.
    13  *
    14  * Create your own  WordPressdotorg\Theme\entry_meta() function to override in a child theme.
    15  */
    16 function entry_meta() {
    17     if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
    18         $time_string = sprintf( '<a href="%1$s" rel="bookmark">%2$s</a>',
    19             esc_url( get_permalink() ),
    20             get_entry_date()
    21         );
     11    /**
     12     * Prints HTML with meta information for the categories, tags.
     13     *
     14     * Create your own  WordPressdotorg\Theme\entry_meta() function to override in a child theme.
     15     */
     16    function entry_meta() {
     17        if ( in_array( get_post_type(), array( 'post', 'attachment' ), true ) ) {
     18            $time_string = sprintf(
     19                '<a href="%1$s" rel="bookmark">%2$s</a>',
     20                esc_url( get_permalink() ),
     21                get_entry_date()
     22            );
    2223
    23         $author_string = sprintf(
    24             '<span class="entry-author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
    25             esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    26             get_the_author()
    27         );
     24            $author_string = sprintf(
     25                '<span class="entry-author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
     26                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
     27                get_the_author()
     28            );
    2829
    29         printf(
    30             /* translators: 1: post date 2: post author */
    31             '<span class="posted-on">' . __( 'Posted on %1$s by %2$s.', 'wporg' ) . '</span>',
    32             $time_string,
    33             $author_string
    34         );
     30            // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped
     31            printf(
     32                /* translators: 1: post date 2: post author */
     33                '<span class="posted-on">' . __( 'Posted on %1$s by %2$s.', 'wporg' ) . '</span>',
     34                $time_string,
     35                $author_string
     36            );
     37            // phpcs:enable WordPress.XSS.EscapeOutput.OutputNotEscaped
     38        }
     39
     40        $format = get_post_format();
     41        if ( current_theme_supports( 'post-formats', $format ) ) {
     42            printf(
     43                '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
     44                sprintf( '<span class="screen-reader-text">%s </span>', esc_html_x( 'Format', 'Used before post format.', 'wporg' ) ),
     45                esc_url( get_post_format_link( $format ) ),
     46                esc_html( get_post_format_string( $format ) )
     47            );
     48        }
     49
     50        if ( 'post' === get_post_type() ) {
     51            entry_taxonomies();
     52        }
     53
     54        if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
     55            echo '<span class="comments-link">';
     56            comments_popup_link( sprintf(
     57                /* translators: Post title. */
     58                __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'wporg' ),
     59                get_the_title()
     60            ) );
     61            echo '</span>';
     62        }
    3563    }
    36 
    37     $format = get_post_format();
    38     if ( current_theme_supports( 'post-formats', $format ) ) {
    39         printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
    40             sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'wporg' ) ),
    41             esc_url( get_post_format_link( $format ) ),
    42             get_post_format_string( $format )
    43         );
    44     }
    45 
    46     if ( 'post' === get_post_type() ) {
    47         entry_taxonomies();
    48     }
    49 
    50     if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    51         echo '<span class="comments-link">';
    52         comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'wporg' ), get_the_title() ) );
    53         echo '</span>';
    54     }
    55 }
    5664endif;
    5765
     
    6977        }
    7078
    71         return sprintf( $time_string,
     79        return sprintf(
     80            $time_string,
    7281            esc_attr( get_the_date( 'c' ) ),
    7382            get_the_date(),
     
    8594     */
    8695    function entry_date() {
    87         printf( '<span class="posted-on">%1$s <a href="%2$s" rel="bookmark">%3$s</a></span>',
    88             _x( 'Posted on', 'Used before publish date.', 'wporg' ),
     96        printf(
     97            '<span class="posted-on">%1$s <a href="%2$s" rel="bookmark">%3$s</a></span>',
     98            esc_html_x( 'Posted on', 'Used before publish date.', 'wporg' ),
    8999            esc_url( get_permalink() ),
    90             get_entry_date()
     100            get_entry_date() // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
    91101        );
    92102    }
     
    94104
    95105if ( ! function_exists( __NAMESPACE__ . '\entry_taxonomies' ) ) :
    96 /**
    97  * Prints HTML with category and tags for current post.
    98  *
    99  * Create your own WordPressdotorg\Theme\entry_taxonomies() function to override in a child theme.
    100  */
    101 function entry_taxonomies() {
    102     $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'wporg' ) );
    103     if ( $categories_list && categorized_blog() ) {
    104         printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
    105             _x( 'Categories', 'Used before category names.', 'wporg' ),
    106             $categories_list
    107         );
     106    /**
     107     * Prints HTML with category and tags for current post.
     108     *
     109     * Create your own WordPressdotorg\Theme\entry_taxonomies() function to override in a child theme.
     110     */
     111    function entry_taxonomies() {
     112        $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'wporg' ) );
     113        if ( $categories_list && categorized_blog() ) {
     114            printf(
     115                '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
     116                esc_html_x( 'Categories', 'Used before category names.', 'wporg' ),
     117                $categories_list // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
     118            );
     119        }
     120
     121        $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wporg' ) );
     122        if ( $tags_list ) {
     123            printf(
     124                '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
     125                esc_html_x( 'Tags', 'Used before tag names.', 'wporg' ),
     126                $tags_list // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
     127            );
     128        }
    108129    }
    109 
    110     $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wporg' ) );
    111     if ( $tags_list ) {
    112         printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
    113             _x( 'Tags', 'Used before tag names.', 'wporg' ),
    114             $tags_list
    115         );
    116     }
    117 }
    118130endif;
    119131
    120132if ( ! function_exists( __NAMESPACE__ . '\categorized_blog' ) ) :
    121 /**
    122  * Determines whether blog/site has more than one category.
    123  *
    124  * Create your own  WordPressdotorg\Theme\categorized_blog() function to override in a child theme.
    125  *
    126  * @return bool True if there is more than one category, false otherwise.
    127  */
    128 function categorized_blog() {
    129     if ( false === ( $all_the_cool_cats = get_transient( 'wporg_categories' ) ) ) {
    130         // Create an array of all the categories that are attached to posts.
    131         $all_the_cool_cats = get_categories( array(
    132             'fields'     => 'ids',
    133             // We only need to know if there is more than one category.
    134             'number'     => 2,
    135         ) );
     133    /**
     134     * Determines whether blog/site has more than one category.
     135     *
     136     * Create your own  WordPressdotorg\Theme\categorized_blog() function to override in a child theme.
     137     *
     138     * @return bool True if there is more than one category, false otherwise.
     139     */
     140    function categorized_blog() {
     141        $all_the_cool_cats = get_transient( 'wporg_categories' );
    136142
    137         // Count the number of categories that are attached to the posts.
    138         $all_the_cool_cats = count( $all_the_cool_cats );
     143        if ( false === $all_the_cool_cats ) {
     144            // Create an array of all the categories that are attached to posts.
     145            $all_the_cool_cats = get_categories( array(
     146                'fields' => 'ids',
     147                // We only need to know if there is more than one category.
     148                'number' => 2,
     149            ) );
    139150
    140         set_transient( 'wporg_categories', $all_the_cool_cats );
     151            // Count the number of categories that are attached to the posts.
     152            $all_the_cool_cats = count( $all_the_cool_cats );
     153
     154            set_transient( 'wporg_categories', $all_the_cool_cats );
     155        }
     156
     157        if ( $all_the_cool_cats > 1 ) {
     158            // This blog has more than 1 category so wporg_categorized_blog should return true.
     159            return true;
     160        } else {
     161            // This blog has only 1 category so wporg_categorized_blog should return false.
     162            return false;
     163        }
    141164    }
    142 
    143     if ( $all_the_cool_cats > 1 ) {
    144         // This blog has more than 1 category so wporg_categorized_blog should return true.
    145         return true;
    146     } else {
    147         // This blog has only 1 category so wporg_categorized_blog should return false.
    148         return false;
    149     }
    150 }
    151165endif;
    152166
     
    163177}
    164178add_action( 'edit_category', __NAMESPACE__ . '\category_transient_flusher' );
    165 add_action( 'save_post',     __NAMESPACE__ . '\category_transient_flusher' );
     179add_action( 'save_post', __NAMESPACE__ . '\category_transient_flusher' );
Note: See TracChangeset for help on using the changeset viewer.