Making WordPress.org


Ignore:
Timestamp:
12/18/2017 05:42:35 PM (7 years ago)
Author:
obenland
Message:

Plugins: Conform to WPCS.

File:
1 edited

Legend:

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

    r6251 r6284  
    99
    1010namespace WordPressdotorg\Plugin_Directory\Theme;
     11
    1112use WordPressdotorg\Plugin_Directory\Template;
    1213use WordPressdotorg\Plugin_Directory\Tools;
    1314
    14 // Returns an absolute url to the current url, no matter what that actually is.
    15 function wporg_plugins_self_link() {
    16     $site_path = preg_replace( '!^' . preg_quote( parse_url( home_url(), PHP_URL_PATH ), '!' ) . '!', '', $_SERVER['REQUEST_URI'] );
    17     return home_url( $site_path );
    18 }
    19 
    20 function wporg_plugins_template_last_updated() {
    21     return '<span title="' . get_the_time('Y-m-d') . '">' . sprintf( _x( '%s ago', 'wporg-plugins' ), human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) ) . '</span>';
    22 }
    23 
    24 function wporg_plugins_template_compatible_up_to() {
    25     $tested = get_post_meta( get_the_id(), 'tested', true ) ;
    26     if ( ! $tested ) {
    27         $tested = _x( 'unknown', 'unknown version', 'wporg-plugins' );
    28     }
    29     return esc_html( $tested );
    30 }
    31 
    32 function wporg_plugins_template_requires() {
    33     return esc_html( get_post_meta( get_the_id(), 'requires', true ) );
    34 }
    35 
    36 function wporg_plugins_the_version() {
    37     return esc_html( get_post_meta( get_the_id(), 'version', true ) );
    38 }
    39 
    40 function wporg_plugins_download_link() {
    41     return esc_url( Template::download_link( get_the_id() ) );
    42 }
    43 
     15/**
     16 * Returns a list of authors.
     17 *
     18 * @return string
     19 */
    4420function wporg_plugins_template_authors() {
    4521    $contributors = get_post_meta( get_the_id(), 'contributors', true );
     
    5834
    5935    $author_links = array();
    60     $and_more = false;
     36    $and_more     = false;
    6137    foreach ( $authors as $user ) {
    6238        $author_links[] = sprintf( '<a href="%s">%s</a>', 'https://profiles.wordpress.org/' . $user->user_nicename . '/', $user->display_name );
     
    6844
    6945    if ( $and_more ) {
    70         return sprintf( '<cite> By: %s, and others.</cite>', implode(', ', $author_links ) );
     46        return sprintf( '<cite> By: %s, and others.</cite>', implode( ', ', $author_links ) );
    7147    } else {
    72         return sprintf( '<cite> By: %s</cite>', implode(', ', $author_links ) );
    73     }
    74 }
    75 
     48        return sprintf( '<cite> By: %s</cite>', implode( ', ', $author_links ) );
     49    }
     50}
    7651
    7752/**
     
    8156 */
    8257function the_plugin_banner( $post = null ) {
    83     echo Template::get_plugin_banner( $post, 'html' );
     58    echo Template::get_plugin_banner( $post, 'html' ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
    8459}
    8560
     
    9570
    9671    $is_favorited = Tools::favorited_plugin( get_post( $post ) );
    97 ?>
    98 <div class="plugin-favorite">
    99     <a href="<?php echo esc_url( Template::get_favorite_link() ); ?>" class="plugin-favorite-heart<?php echo $is_favorited ? ' favorited' : ''; ?>">
     72    ?>
     73    <div class="plugin-favorite">
     74        <a href="<?php echo esc_url( Template::get_favorite_link() ); ?>" class="plugin-favorite-heart<?php echo $is_favorited ? ' favorited' : ''; ?>">
    10075        <span class="screen-reader-text">
    10176            <?php
    10277            if ( $is_favorited ) {
    10378                /* translators: %s: plugin name */
    104                 printf( __( 'Unfavorite %s', 'wporg-plugins' ), get_the_title() );
     79                printf( esc_html__( 'Unfavorite %s', 'wporg-plugins' ), get_the_title() );
    10580            } else {
    10681                /* translators: %s: plugin name */
    107                 printf( __( 'Favorite %s', 'wporg-plugins' ), get_the_title() );
     82                printf( esc_html__( 'Favorite %s', 'wporg-plugins' ), get_the_title() );
    10883            }
    10984            ?>
    11085        </span>
    111     </a>
    112     <script>
    113         jQuery( '.plugin-favorite-heart' )
    114             .on( 'click touchstart animationend', function() {
    115                 jQuery( this ).toggleClass( 'is-animating' );
    116             } )
    117             .on( 'click', function() {
    118                 jQuery( this ).toggleClass( 'favorited' );
    119             } );
    120     </script>
    121 </div>
    122 <?php
     86        </a>
     87        <script>
     88            jQuery( '.plugin-favorite-heart' )
     89                .on( 'click touchstart animationend', function () {
     90                    jQuery( this ).toggleClass( 'is-animating' );
     91                } )
     92                .on( 'click', function () {
     93                    jQuery( this ).toggleClass( 'favorited' );
     94                } );
     95        </script>
     96    </div>
     97    <?php
    12398}
    12499
     
    133108    $url    = get_post_meta( $post->ID, 'header_author_uri', true );
    134109    $author = strip_tags( get_post_meta( $post->ID, 'header_author', true ) ) ?: get_the_author();
    135     $author = esc_html( Template::encode( $author ) );
    136110    $author = $url ? '<a class="url fn n" rel="nofollow" href="' . esc_url( $url ) . '">' . $author . '</a>' : $author;
    137111
    138     printf( _x( 'By %s', 'post author', 'wporg-plugins' ), '<span class="author vcard">' . $author . '</span>' );
     112    /* translators: post author. */
     113    printf( esc_html_x( 'By %s', 'post author', 'wporg-plugins' ), '<span class="author vcard">' . wp_kses_post( $author ) . '</span>' );
    139114}
    140115
     
    145120 */
    146121function the_active_plugin_notice( $post = null ) {
    147     if ( ! in_array( get_post_status( $post ), ['rejected', 'closed'], true ) ) {
    148         echo get_plugin_status_notice( $post );
     122    if ( ! in_array( get_post_status( $post ), [ 'rejected', 'closed' ], true ) ) {
     123        echo wp_kses_post( get_plugin_status_notice( $post ) );
    149124    };
    150125}
     
    156131 */
    157132function the_closed_plugin_notice( $post = null ) {
    158     echo get_closed_plugin_notice( $post );
     133    echo wp_kses_post( get_closed_plugin_notice( $post ) );
    159134}
    160135
     
    169144    $notice = '';
    170145
    171     if ( in_array( get_post_status( $post ), ['rejected', 'closed'], true ) ) {
     146    if ( in_array( get_post_status( $post ), [ 'rejected', 'closed' ], true ) ) {
    172147        $notice = get_plugin_status_notice( $post );
    173148
    174         if ( get_current_user_id() == $post->post_author ) {
     149        if ( get_current_user_id() === (int) $post->post_author ) {
    175150            $info_notice = '<div class="plugin-notice notice notice-info notice-alt"><p>%s</p></div><!-- .plugin-notice -->';
    176151            $message     = sprintf(
    177             /* translators: 1: plugins@wordpress.org */
     152                /* translators: 1: plugins@wordpress.org */
    178153                __( 'If you did not request this change, please contact <a href="mailto:%1$s">%1$s</a> for a status. All developers with commit access are contacted when a plugin is closed, with the reasons why, so check your spam email too.', 'wporgplugins' ),
    179154                'plugins@wordpress.org'
     
    244219            $closed_date = get_post_meta( get_the_ID(), 'plugin_closed_date', true );
    245220            if ( ! empty( $closed_date ) ) {
     221                /* translators: Closing date. */
    246222                $message = sprintf( __( 'This plugin was closed on %s and is no longer available for download.', 'wporg-plugins' ), mysql2date( get_option( 'date_format' ), $closed_date ) );
    247223            } else {
Note: See TracChangeset for help on using the changeset viewer.