Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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-admin/includes/plugin-install.php

    r42228 r42343  
    146146
    147147        $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
    148         if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
     148        if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
    149149            $url = set_url_scheme( $url, 'https' );
     150        }
    150151
    151152        $http_args = array(
    152             'timeout' => 15,
     153            'timeout'    => 15,
    153154            'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
    154             'body' => array(
    155                 'action' => $action,
    156                 'request' => serialize( $args )
    157             )
     155            'body'       => array(
     156                'action'  => $action,
     157                'request' => serialize( $args ),
     158            ),
    158159        );
    159         $request = wp_remote_post( $url, $http_args );
     160        $request   = wp_remote_post( $url, $http_args );
    160161
    161162        if ( $ssl && is_wp_error( $request ) ) {
     
    171172        }
    172173
    173         if ( is_wp_error($request) ) {
    174             $res = new WP_Error( 'plugins_api_failed',
     174        if ( is_wp_error( $request ) ) {
     175            $res = new WP_Error(
     176                'plugins_api_failed',
    175177                sprintf(
    176178                    /* translators: %s: support forums URL */
     
    183185            $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
    184186            if ( ! is_object( $res ) && ! is_array( $res ) ) {
    185                 $res = new WP_Error( 'plugins_api_failed',
     187                $res = new WP_Error(
     188                    'plugins_api_failed',
    186189                    sprintf(
    187190                        /* translators: %s: support forums URL */
     
    193196            }
    194197        }
    195     } elseif ( !is_wp_error($res) ) {
     198    } elseif ( ! is_wp_error( $res ) ) {
    196199        $res->external = true;
    197200    }
     
    218221 */
    219222function install_popular_tags( $args = array() ) {
    220     $key = md5(serialize($args));
    221     if ( false !== ($tags = get_site_transient('poptags_' . $key) ) )
     223    $key = md5( serialize( $args ) );
     224    if ( false !== ( $tags = get_site_transient( 'poptags_' . $key ) ) ) {
    222225        return $tags;
    223 
    224     $tags = plugins_api('hot_tags', $args);
    225 
    226     if ( is_wp_error($tags) )
     226    }
     227
     228    $tags = plugins_api( 'hot_tags', $args );
     229
     230    if ( is_wp_error( $tags ) ) {
    227231        return $tags;
     232    }
    228233
    229234    set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
     
    242247
    243248    <div class="plugins-popular-tags-wrapper">
    244     <h2><?php _e( 'Popular tags' ) ?></h2>
    245     <p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ) ?></p>
     249    <h2><?php _e( 'Popular tags' ); ?></h2>
     250    <p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p>
    246251    <?php
    247252
     
    249254
    250255    echo '<p class="popular-tags">';
    251     if ( is_wp_error($api_tags) ) {
     256    if ( is_wp_error( $api_tags ) ) {
    252257        echo $api_tags->get_error_message();
    253258    } else {
     
    255260        $tags = array();
    256261        foreach ( (array) $api_tags as $tag ) {
    257             $url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
    258             $data = array(
    259                 'link' => esc_url( $url ),
    260                 'name' => $tag['name'],
    261                 'slug' => $tag['slug'],
    262                 'id' => sanitize_title_with_dashes( $tag['name'] ),
    263                 'count' => $tag['count']
     262            $url                  = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
     263            $data                 = array(
     264                'link'  => esc_url( $url ),
     265                'name'  => $tag['name'],
     266                'slug'  => $tag['slug'],
     267                'id'    => sanitize_title_with_dashes( $tag['name'] ),
     268                'count' => $tag['count'],
    264269            );
    265270            $tags[ $tag['name'] ] = (object) $data;
    266271        }
    267         echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin'), 'multiple_text' => __('%s plugins') ) );
     272        echo wp_generate_tag_cloud(
     273            $tags, array(
     274                'single_text'   => __( '%s plugin' ),
     275                'multiple_text' => __( '%s plugins' ),
     276            )
     277        );
    268278    }
    269279    echo '</p><br class="clear" /></div>';
     
    281291    $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
    282292    $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
    283     ?><form class="search-form search-plugins" method="get">
     293    ?>
     294    <form class="search-form search-plugins" method="get">
    284295        <input type="hidden" name="tab" value="search" />
    285296        <label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label>
     
    290301        </select>
    291302        <label><span class="screen-reader-text"><?php _e( 'Search Plugins' ); ?></span>
    292             <input type="search" name="s" value="<?php echo esc_attr( $term ) ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />
     303            <input type="search" name="s" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />
    293304        </label>
    294305        <?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?>
    295     </form><?php
     306    </form>
     307    <?php
    296308}
    297309
    298310/**
    299311 * Upload from zip
     312 *
    300313 * @since 2.8.0
    301314 */
     
    303316?>
    304317<div class="upload-plugin">
    305     <p class="install-help"><?php _e('If you have a plugin in a .zip format, you may install it by uploading it here.'); ?></p>
    306     <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-plugin'); ?>">
     318    <p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install it by uploading it here.' ); ?></p>
     319    <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>">
    307320        <?php wp_nonce_field( 'plugin-upload' ); ?>
    308321        <label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label>
     
    316329/**
    317330 * Show a username form for the favorites page
     331 *
    318332 * @since 3.5.0
    319  *
    320333 */
    321334function install_plugins_favorites_form() {
     
    347360
    348361    switch ( current_filter() ) {
    349         case 'install_plugins_favorites' :
     362        case 'install_plugins_favorites':
    350363            if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
    351364                return;
    352365            }
    353366            break;
    354         case 'install_plugins_recommended' :
     367        case 'install_plugins_recommended':
    355368            echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
    356369            break;
    357         case 'install_plugins_beta' :
     370        case 'install_plugins_beta':
    358371            printf(
    359372                '<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>',
     
    386399 * }
    387400 */
    388 function install_plugin_install_status($api, $loop = false) {
     401function install_plugin_install_status( $api, $loop = false ) {
    389402    // This function is called recursively, $loop prevents further loops.
    390     if ( is_array($api) )
     403    if ( is_array( $api ) ) {
    391404        $api = (object) $api;
     405    }
    392406
    393407    // Default to a "new" plugin
    394     $status = 'install';
    395     $url = false;
     408    $status      = 'install';
     409    $url         = false;
    396410    $update_file = false;
    397411
     
    400414     * and has an update awaiting it.
    401415     */
    402     $update_plugins = get_site_transient('update_plugins');
     416    $update_plugins = get_site_transient( 'update_plugins' );
    403417    if ( isset( $update_plugins->response ) ) {
    404         foreach ( (array)$update_plugins->response as $file => $plugin ) {
     418        foreach ( (array) $update_plugins->response as $file => $plugin ) {
    405419            if ( $plugin->slug === $api->slug ) {
    406                 $status = 'update_available';
     420                $status      = 'update_available';
    407421                $update_file = $file;
    408                 $version = $plugin->new_version;
    409                 if ( current_user_can('update_plugins') )
    410                     $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
     422                $version     = $plugin->new_version;
     423                if ( current_user_can( 'update_plugins' ) ) {
     424                    $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file );
     425                }
    411426                break;
    412427            }
     
    416431    if ( 'install' == $status ) {
    417432        if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
    418             $installed_plugin = get_plugins('/' . $api->slug);
    419             if ( empty($installed_plugin) ) {
    420                 if ( current_user_can('install_plugins') )
    421                     $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
     433            $installed_plugin = get_plugins( '/' . $api->slug );
     434            if ( empty( $installed_plugin ) ) {
     435                if ( current_user_can( 'install_plugins' ) ) {
     436                    $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
     437                }
    422438            } else {
    423                 $key = array_keys( $installed_plugin );
    424                 $key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
     439                $key         = array_keys( $installed_plugin );
     440                $key         = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
    425441                $update_file = $api->slug . '/' . $key;
    426                 if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){
     442                if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) {
    427443                    $status = 'latest_installed';
    428                 } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
    429                     $status = 'newer_installed';
     444                } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) {
     445                    $status  = 'newer_installed';
    430446                    $version = $installed_plugin[ $key ]['Version'];
    431447                } else {
    432448                    //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
    433449                    if ( ! $loop ) {
    434                         delete_site_transient('update_plugins');
     450                        delete_site_transient( 'update_plugins' );
    435451                        wp_update_plugins();
    436                         return install_plugin_install_status($api, true);
     452                        return install_plugin_install_status( $api, true );
    437453                    }
    438454                }
     
    440456        } else {
    441457            // "install" & no directory with that slug
    442             if ( current_user_can('install_plugins') )
    443                 $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
    444         }
    445     }
    446     if ( isset($_GET['from']) )
     458            if ( current_user_can( 'install_plugins' ) ) {
     459                $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
     460            }
     461        }
     462    }
     463    if ( isset( $_GET['from'] ) ) {
    447464        $url .= '&amp;from=' . urlencode( wp_unslash( $_GET['from'] ) );
     465    }
    448466
    449467    $file = $update_file;
     
    465483    }
    466484
    467     $api = plugins_api( 'plugin_information', array(
    468         'slug' => wp_unslash( $_REQUEST['plugin'] ),
    469         'is_ssl' => is_ssl(),
    470         'fields' => array(
    471             'banners' => true,
    472             'reviews' => true,
    473             'downloaded' => false,
    474             'active_installs' => true
     485    $api = plugins_api(
     486        'plugin_information', array(
     487            'slug'   => wp_unslash( $_REQUEST['plugin'] ),
     488            'is_ssl' => is_ssl(),
     489            'fields' => array(
     490                'banners'         => true,
     491                'reviews'         => true,
     492                'downloaded'      => false,
     493                'active_installs' => true,
     494            ),
    475495        )
    476     ) );
     496    );
    477497
    478498    if ( is_wp_error( $api ) ) {
     
    481501
    482502    $plugins_allowedtags = array(
    483         'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),
    484         'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ),
    485         'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
    486         'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ),
    487         'p' => array(), 'br' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
    488         'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
    489         'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
     503        'a'          => array(
     504            'href'   => array(),
     505            'title'  => array(),
     506            'target' => array(),
     507        ),
     508        'abbr'       => array( 'title' => array() ),
     509        'acronym'    => array( 'title' => array() ),
     510        'code'       => array(),
     511        'pre'        => array(),
     512        'em'         => array(),
     513        'strong'     => array(),
     514        'div'        => array( 'class' => array() ),
     515        'span'       => array( 'class' => array() ),
     516        'p'          => array(),
     517        'br'         => array(),
     518        'ul'         => array(),
     519        'ol'         => array(),
     520        'li'         => array(),
     521        'h1'         => array(),
     522        'h2'         => array(),
     523        'h3'         => array(),
     524        'h4'         => array(),
     525        'h5'         => array(),
     526        'h6'         => array(),
     527        'img'        => array(
     528            'src'   => array(),
     529            'class' => array(),
     530            'alt'   => array(),
     531        ),
    490532        'blockquote' => array( 'cite' => true ),
    491533    );
    492534
    493535    $plugins_section_titles = array(
    494         'description'  => _x( 'Description',  'Plugin installer section title' ),
     536        'description'  => _x( 'Description', 'Plugin installer section title' ),
    495537        'installation' => _x( 'Installation', 'Plugin installer section title' ),
    496         'faq'          => _x( 'FAQ',          'Plugin installer section title' ),
    497         'screenshots'  => _x( 'Screenshots',  'Plugin installer section title' ),
    498         'changelog'    => _x( 'Changelog',    'Plugin installer section title' ),
    499         'reviews'      => _x( 'Reviews',      'Plugin installer section title' ),
    500         'other_notes'  => _x( 'Other Notes',  'Plugin installer section title' )
     538        'faq'          => _x( 'FAQ', 'Plugin installer section title' ),
     539        'screenshots'  => _x( 'Screenshots', 'Plugin installer section title' ),
     540        'changelog'    => _x( 'Changelog', 'Plugin installer section title' ),
     541        'reviews'      => _x( 'Reviews', 'Plugin installer section title' ),
     542        'other_notes'  => _x( 'Other Notes', 'Plugin installer section title' ),
    501543    );
    502544
    503545    // Sanitize HTML
    504546    foreach ( (array) $api->sections as $section_name => $content ) {
    505         $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
     547        $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags );
    506548    }
    507549
     
    517559    if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
    518560        $section_titles = array_keys( (array) $api->sections );
    519         $section = reset( $section_titles );
     561        $section        = reset( $section_titles );
    520562    }
    521563
     
    526568    if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
    527569        $_with_banner = 'with-banner';
    528         $low  = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
    529         $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
     570        $low          = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
     571        $high         = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
    530572        ?>
    531573        <style type="text/css">
     
    557599        }
    558600
    559         $class = ( $section_name === $section ) ? ' class="current"' : '';
    560         $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
    561         $href = esc_url( $href );
     601        $class       = ( $section_name === $section ) ? ' class="current"' : '';
     602        $href        = add_query_arg(
     603            array(
     604                'tab'     => $tab,
     605                'section' => $section_name,
     606            )
     607        );
     608        $href        = esc_url( $href );
    562609        $san_section = esc_attr( $section_name );
    563610        echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
     
    592639                <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
    593640            <?php } if ( isset( $api->active_installs ) ) { ?>
    594                 <li><strong><?php _e( 'Active Installations:' ); ?></strong> <?php
    595                     if ( $api->active_installs >= 1000000 ) {
    596                         _ex( '1+ Million', 'Active plugin installations' );
    597                     } elseif ( 0 == $api->active_installs ) {
    598                         _ex( 'Less Than 10', 'Active plugin installations' );
    599                     } else {
    600                         echo number_format_i18n( $api->active_installs ) . '+';
    601                     }
    602                     ?></li>
     641                <li><strong><?php _e( 'Active Installations:' ); ?></strong>
     642                                        <?php
     643                                        if ( $api->active_installs >= 1000000 ) {
     644                                            _ex( '1+ Million', 'Active plugin installations' );
     645                                        } elseif ( 0 == $api->active_installs ) {
     646                                            _ex( 'Less Than 10', 'Active plugin installations' );
     647                                        } else {
     648                                            echo number_format_i18n( $api->active_installs ) . '+';
     649                                        }
     650                    ?>
     651                    </li>
    603652            <?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
    604653                <li><a target="_blank" href="<?php echo __( 'https://wordpress.org/plugins/' ) . $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a></li>
     
    611660        <?php if ( ! empty( $api->rating ) ) { ?>
    612661            <h3><?php _e( 'Average Rating' ); ?></h3>
    613             <?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?>
     662            <?php
     663            wp_star_rating(
     664                array(
     665                    'rating' => $api->rating,
     666                    'type'   => 'percent',
     667                    'number' => $api->num_ratings,
     668                )
     669            );
     670?>
    614671            <p aria-hidden="true" class="fyi-description"><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></p>
    615         <?php }
    616 
    617         if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { ?>
     672        <?php
     673}
     674
     675if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
     676        ?>
    618677            <h3><?php _e( 'Reviews' ); ?></h3>
    619678            <p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p>
     
    623682                $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
    624683                /* translators: 1: number of stars (used to determine singular/plural), 2: number of reviews */
    625                 $aria_label = esc_attr( sprintf( _n( 'Reviews with %1$d star: %2$s. Opens in a new window.', 'Reviews with %1$d stars: %2$s. Opens in a new window.', $key ),
    626                     $key,
    627                     number_format_i18n( $ratecount )
    628                 ) );
     684                $aria_label = esc_attr(
     685                    sprintf(
     686                        _n( 'Reviews with %1$d star: %2$s. Opens in a new window.', 'Reviews with %1$d stars: %2$s. Opens in a new window.', $key ),
     687                        $key,
     688                        number_format_i18n( $ratecount )
     689                    )
     690                );
    629691                ?>
    630692                <div class="counter-container">
     
    640702                <?php
    641703            }
    642         }
    643         if ( ! empty( $api->contributors ) ) { ?>
     704}
     705if ( ! empty( $api->contributors ) ) {
     706        ?>
    644707            <h3><?php _e( 'Contributors' ); ?></h3>
    645708            <ul class="contributors">
     
    702765            case 'update_available':
    703766                if ( $status['url'] ) {
    704                     echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
     767                    echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
    705768                }
    706769                break;
    707770            case 'newer_installed':
    708771                /* translators: %s: Plugin version */
    709                 echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed'), $status['version'] ) . '</a>';
     772                echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
    710773                break;
    711774            case 'latest_installed':
Note: See TracChangeset for help on using the changeset viewer.