Making WordPress.org


Ignore:
Timestamp:
10/07/2016 06:16:29 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Remove unused (and irrelevant) template tags which don't apply to the plugin directory.

See #1719

File:
1 edited

Legend:

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

    r3209 r4199  
    1010namespace WordPressdotorg\Plugin_Directory\Theme;
    1111use WordPressdotorg\Plugin_Directory\Template;
    12 
    13 if ( ! function_exists( 'wporg_plugins_posted_on' ) ) :
    14 /**
    15  * Prints HTML with meta information for the current post-date/time and author.
    16  */
    17 function wporg_plugins_posted_on() {
    18         $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    19         if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    20                 $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    21         }
    22 
    23         $time_string = sprintf( $time_string,
    24                 esc_attr( get_the_date( 'c' ) ),
    25                 esc_html( get_the_date() ),
    26                 esc_attr( get_the_modified_date( 'c' ) ),
    27                 esc_html( get_the_modified_date() )
    28         );
    29 
    30         $posted_on = sprintf(
    31                 esc_html_x( 'Posted on %s', 'post date', 'wporg-plugins' ),
    32                 '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    33         );
    34 
    35         $byline = sprintf(
    36                 esc_html_x( 'by %s', 'post author', 'wporg-plugins' ),
    37                 '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
    38         );
    39 
    40         echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
    41 
    42 }
    43 endif;
    44 
    45 if ( ! function_exists( 'wporg_plugins_entry_footer' ) ) :
    46 /**
    47  * Prints HTML with meta information for the categories, tags and comments.
    48  */
    49 function wporg_plugins_entry_footer() {
    50         // Hide category and tag text for pages.
    51         if ( 'post' === get_post_type() ) {
    52                 /* translators: used between list items, there is a space after the comma */
    53                 $categories_list = get_the_category_list( esc_html__( ', ', 'wporg-plugins' ) );
    54                 if ( $categories_list && wporg_plugins_categorized_blog() ) {
    55                         printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'wporg-plugins' ) . '</span>', $categories_list ); // WPCS: XSS OK.
    56                 }
    57 
    58                 /* translators: used between list items, there is a space after the comma */
    59                 $tags_list = get_the_tag_list( '', esc_html__( ', ', 'wporg-plugins' ) );
    60                 if ( $tags_list ) {
    61                         printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'wporg-plugins' ) . '</span>', $tags_list ); // WPCS: XSS OK.
    62                 }
    63         }
    64 
    65         if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    66                 echo '<span class="comments-link">';
    67                 /* translators: %s: post title */
    68                 comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'wporg-plugins' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) );
    69                 echo '</span>';
    70         }
    71 
    72         edit_post_link(
    73                 sprintf(
    74                         /* translators: %s: Name of current post */
    75                         esc_html__( 'Edit %s', 'wporg-plugins' ),
    76                         the_title( '<span class="screen-reader-text">"', '"</span>', false )
    77                 ),
    78                 '<span class="edit-link">',
    79                 '</span>'
    80         );
    81 }
    82 endif;
    83 
    84 /**
    85  * Returns true if a blog has more than 1 category.
    86  *
    87  * @return bool
    88  */
    89 function wporg_plugins_categorized_blog() {
    90         if ( false === ( $all_the_cool_cats = get_transient( 'wporg_plugins_categories' ) ) ) {
    91                 // Create an array of all the categories that are attached to posts.
    92                 $all_the_cool_cats = get_categories( array(
    93                         'fields'     => 'ids',
    94                         'hide_empty' => 1,
    95                         // We only need to know if there is more than one category.
    96                         'number'     => 2,
    97                 ) );
    98 
    99                 // Count the number of categories that are attached to the posts.
    100                 $all_the_cool_cats = count( $all_the_cool_cats );
    101 
    102                 set_transient( 'wporg_plugins_categories', $all_the_cool_cats );
    103         }
    104 
    105         if ( $all_the_cool_cats > 1 ) {
    106                 // This blog has more than 1 category so wporg_plugins_categorized_blog should return true.
    107                 return true;
    108         } else {
    109                 // This blog has only 1 category so wporg_plugins_categorized_blog should return false.
    110                 return false;
    111         }
    112 }
    113 
    114 /**
    115  * Flush out the transients used in wporg_plugins_categorized_blog.
    116  */
    117 function wporg_plugins_category_transient_flusher() {
    118         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    119                 return;
    120         }
    121         // Like, beat it. Dig?
    122         delete_transient( 'wporg_plugins_categories' );
    123 }
    124 add_action( 'edit_category', __NAMESPACE__ . '\wporg_plugins_category_transient_flusher' );
    125 add_action( 'save_post',     __NAMESPACE__ . '\wporg_plugins_category_transient_flusher' );
    126 
    12712
    12813// Returns an absolute url to the current url, no matter what that actually is.
Note: See TracChangeset for help on using the changeset viewer.