Making WordPress.org

Changeset 2994


Ignore:
Timestamp:
04/21/2016 07:41:53 PM (10 years ago)
Author:
obenland
Message:

Plugin Directory: Housekeeping.

  • Updates and corrects doc blocks.
  • Simplifies overqualified class references.
  • Corrects function args and return types.
  • Adds missing labels to input elements.
  • Makes sure variables are set before using them.

See #1584.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php

    r2982 r2994  
    3131
    3232                add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
    33                 add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ), 10, 2 );
     33                add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ) );
    3434
    3535                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
     
    158158        /**
    159159         * Filter the query in wp-admin to list only plugins relevant to the current user.
     160         *
     161         * @param \WP_Query $query
    160162         */
    161163        public function pre_get_posts( $query ) {
    162                 global $wpdb;
    163164                if ( ! $query->is_main_query() ) {
    164165                        return;
     
    186187         *
    187188         * @ignore
     189         *
     190         * @param string $where WHERE clause.
     191         * @return string
    188192         */
    189193        public function pre_get_posts_sql_name_or_user( $where ) {
     
    224228         * @param array    $post_states An array of post display states.
    225229         * @param \WP_Post $post        The current post object.
     230         * @return array
    226231         */
    227232        public function post_states( $post_states, $post ) {
     
    310315         *
    311316         * @param int      $post_id The post_id being updated.
    312          * @param \WP_Post $post    The WP_Post object being updated.
    313          */
    314         public function save_plugin_post( $post_id, $post ) {
     317         */
     318        public function save_plugin_post( $post_id ) {
    315319                // Save meta information
    316320                if ( isset( $_POST['tested_with'] ) && isset( $_POST['hidden_tested_with'] ) && $_POST['tested_with'] != $_POST['hidden_tested_with'] ) {
     
    471475                );
    472476
    473                 if ( $comment_auto_approved ) {
     477                if ( $comment_auto_approved && isset( $parent ) ) {
    474478                        $response['supplemental']['parent_approved'] = $parent->comment_ID;
    475479                        $response['supplemental']['parent_post_id']  = $parent->comment_post_ID;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-committers.php

    r2777 r2994  
    8484                                'username' => __( 'Username', 'wporg-plugins' ),
    8585                        ),
    86                         array(),
    8786                        array(),
    8887                        'username',
     
    123122                                        <?php wp_nonce_field( 'add-committer', '_ajax_nonce', false ); ?>
    124123                                        <span id="committer-error" class="notice notice-alt notice-error" style="display:none;"></span>
    125                                         <input type="text" name="add_committer" class="form-required" value="" aria-required="true">
     124                                        <label>
     125                                                <input type="text" name="add_committer" class="form-required" value="" aria-required="true">
     126                                                <span class="screen-reader-text"><?php _e( 'Add a new committer', 'wporg-plugins' ); ?></span>
     127                                        </label>
    126128                                        <input type="button" id="add-committer-submit" class="button" data-wp-lists="add:the-committer-list:add-committer::post_id=<?php echo get_post()->ID; ?>" value="<?php _e( 'Add Committer', 'wporg-plugins' ); ?>">
    127129                                </p>
     
    144146                }
    145147                $user_object->filter = 'display';
    146                 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
     148                list( $columns, $hidden, $primary ) = $this->get_column_info();
    147149
    148150                // Set up the hover actions for this committer.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php

    r2991 r2994  
    88
    99        /**
    10          * Plugin API response about the current plugin displayed.
    11          *
    12          * @var object
    13          */
    14          protected $plugin_meta;
    15 
    16         /**
    17          *
    18          * @global array    $avail_post_stati
    19          * @global WP_Query $wp_query
    20          * @global int      $per_page
    21          * @global string   $mode
     10         *
     11         * @global array     $avail_post_stati
     12         * @global \WP_Query $wp_query
     13         * @global int       $per_page
     14         * @global string    $mode
    2215         */
    2316        public function prepare_items() {
     
    137130                        $classes[] = 'level-0';
    138131                }
    139 
    140                 //@TODO: Switch to using the API class directly (once rewritten), or even better, post meta.
    141                 require_once ABSPATH . '/wp-admin/includes/plugin-install.php';
    142                 $this->plugin_meta = \plugins_api( 'plugin_information', array(
    143                         'slug'   => $post->post_name,
    144                 ) );
    145132                ?>
    146133                <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
     
    172159         */
    173160        public function column_rating( $post ) {
    174                 if ( ! empty( $this->plugin_meta->rating ) && function_exists( 'wporg_get_dashicons_stars' ) ) {
    175                         echo wporg_get_dashicons_stars( $this->plugin_meta->rating / 20 );
     161                $rating = (string) get_post_meta( $post->ID, 'avg_rating', true );
     162                if ( ! empty( $rating ) && function_exists( 'wporg_get_dashicons_stars' ) ) {
     163                        echo wporg_get_dashicons_stars( $rating / 20 );
    176164                }
    177165        }
     
    306294                         *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
    307295                         *                         'Delete Permanently', 'Preview', and 'View'.
    308                          * @param WP_Post $post The post object.
     296                         * @param \WP_Post $post The post object.
    309297                         */
    310298                        $actions = apply_filters( 'page_row_actions', $actions, $post );
     
    319307                         *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
    320308                         *                         'Delete Permanently', 'Preview', and 'View'.
    321                          * @param WP_Post $post The post object.
     309                         * @param \WP_Post $post The post object.
    322310                         */
    323311                        $actions = apply_filters( 'post_row_actions', $actions, $post );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php

    r2929 r2994  
    100100                        $response->add( array(
    101101                                'what' => 'committer',
    102                                 'data' => new \WP_Error( 'error', sprintf( __( 'The user %s does not exist.', 'wporg-plugins' ), '<code>' . $login . '</code>' ) ),
     102                                'data' => new \WP_Error( 'error', __( 'The specified user does not exist.', 'wporg-plugins' ) ),
    103103                        ) );
    104104                        $response->send();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-controls.php

    r2980 r2994  
    5656                        <div id="plugin-status-select" class="plugin-control-select hide-if-js">
    5757                                <input type="hidden" name="hidden_post_status" id="hidden-post-status" value="<?php echo esc_attr( $post->post_status ); ?>">
     58                                <label class="screen-reader-text" for="plugin-status"><?php _e( 'Plugin status', 'wporg-plugins' ); ?></label>
    5859                                <select name="post_status" id="plugin-status">
    5960                                        <?php
     
    9697                        <div id="tested-with-select" class="plugin-control-select hide-if-js">
    9798                                <input type="hidden" name="hidden_tested_with" id="hidden-tested-with" value="<?php echo esc_attr( $tested_up_to ); ?>">
     99                                <label class="screen-reader-text" for="tested-with"><?php _e( 'Version of WordPress it was tested with', 'wporg-plugins' ); ?></label>
    98100                                <select name="tested_with" id="tested-with">
    99101                                        <?php
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-plugin-tags.php

    r2655 r2994  
    88 */
    99class Plugin_Tags {
    10 
    1110        /**
    1211         * Displays the Publish metabox for plugins.
    1312         * The HTML here matches what Core uses.
     13         *
     14         * @param \WP_Post $post
    1415         */
    15         static function display( $post, $box ) {
    16                 $taxonomy = get_taxonomy( 'plugin_tag' );
     16        static function display( $post ) {
    1717                ?>
    1818                <div id="taxonomy-plugin_tag" class="categorydiv">
    1919                        <div id="plugin_tag-all" class="tabs-panel">
    20                                 <?php
    21                                 echo "<input type='hidden' name='tax_input[plugin_tag][]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
    22                                 ?>
     20                                <?php // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. ?>
     21                                <input type='hidden' name='tax_input[plugin_tag][]' value='0' />
    2322                                <ul id="plugin_tagchecklist" data-wp-lists="list:plugin_tag" class="categorychecklist form-no-clear">
    2423                                        <?php wp_terms_checklist( $post->ID, array( 'taxonomy' => 'plugin_tag' ) ); ?>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/class-base.php

    r2985 r2994  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\API;
     3use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    34
    45/**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php

    r2985 r2994  
    5252                        foreach ( $stats as $stat_name => $value ) {
    5353                                if ( 'active_installs' == $stat_name ) {
    54                                         $value = $this->sanitize_active_installs( $value, $plugin );
     54                                        $value = $this->sanitize_active_installs( $value );
    5555                                } elseif ( 'usage' == $stat_name ) {
    5656                                        $value = $this->sanitize_usage_numbers( $value, $plugin );
     
    101101         * unless it's the latest branch, or if there's only one branch which is less than 5%.
    102102         *
    103          * @param array   $usage  An array of the branch usage numbers.
    104          * @param WP_Post $plugin The plugin's WP_Post instance.
     103         * @param array    $usage  An array of the branch usage numbers.
     104         * @param \WP_Post $plugin The plugin's WP_Post instance.
    105105         * @return array An array containing the percentages for the given plugin.
    106106         */
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r2991 r2994  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3use WordPressdotorg\Plugin_Directory\Admin\Customizations;
    34
    45/**
     
    2627                add_filter( 'the_content', array( $this, 'filter_post_content_to_correct_page' ), 1 );
    2728                add_filter( 'rest_api_allowed_post_types', array( $this, 'filter_allowed_post_types' ) );
    28                 add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ), 10, 2 );
     29                add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) );
    2930
    3031                add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 );
     
    3940                // Cannot be included on `admin_init` to allow access to menu hooks
    4041                if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) {
    41                         Admin\Customizations::instance();
     42                        Customizations::instance();
    4243
    4344                        add_action( 'transition_post_status', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'instance' ) );
     
    200201         * Setting up the site requires setting up the theme and proper
    201202         * rewrite permastructs.
    202          *
    203          * @global \WP_Rewrite $wp_rewrite WordPress rewrite component.
    204203         */
    205204        public function activate() {
     205
     206                /**
     207                 * @var \WP_Rewrite $wp_rewrite WordPress rewrite component.
     208                 */
    206209                global $wp_rewrite;
    207210
     
    220223                }
    221224
    222                 // Enable the WordPress.org Plugin Repo Theme.
     225                /**
     226                 * Enable the WordPress.org Plugin Repo Theme.
     227                 *
     228                 * @var \WP_Theme $theme
     229                 */
    223230                foreach ( wp_get_themes() as $theme ) {
    224231                        if ( $theme->get( 'Name' ) === 'WordPress.org Plugins' ) {
     
    398405         *
    399406         * @param mixed $new_value
    400          * @param mixed $old_value
    401407         * @return mixed
    402408         */
    403         public function filter_jetpack_options( $new_value, $old_value ) {
    404                 if ( is_array($new_value) && array_key_exists( 'public', $new_value ) )
     409        public function filter_jetpack_options( $new_value ) {
     410                if ( is_array( $new_value ) && array_key_exists( 'public', $new_value ) )
    405411                        $new_value['public'] = 1;
    406412
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-geopattern-svg.php

    r2621 r2994  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3use RedeyeVentures\GeoPattern\SVG;
    34
    45/**
     
    78 * @package WordPressdotorg\Plugin_Directory
    89 */
    9 class Plugin_Geopattern_SVG extends \RedeyeVentures\GeoPattern\SVG {
     10class Plugin_Geopattern_SVG extends SVG {
    1011
    1112        /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-geopattern-svgtext.php

    r2621 r2994  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3use RedeyeVentures\GeoPattern\SVGElements\Base;
    34
    45/**
     
    78 * @package WordPressdotorg\Plugin_Directory
    89 */
    9 class Plugin_Geopattern_SVGText extends \RedeyeVentures\GeoPattern\SVGElements\Base {
     10class Plugin_Geopattern_SVGText extends Base {
    1011
    1112        /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-geopattern.php

    r2621 r2994  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3use RedeyeVentures\GeoPattern\GeoPattern;
    34
    45require __DIR__ . '/libs/geopattern-1.1.0/geopattern_loader.php';
     
    910 * @package WordPressdotorg\Plugin_Directory
    1011 */
    11 class Plugin_Geopattern extends \RedeyeVentures\GeoPattern\GeoPattern {
     12class Plugin_Geopattern extends GeoPattern {
    1213
    1314        /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php

    r2992 r2994  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3use Michelf\MarkdownExtra;
     4
    35/**
    46 * WordPress.org Plugin Readme Parser.
     
    9193                $line = $this->get_first_nonwhitespace( $contents );
    9294                do {
    93                         $key = $value = null;
     95                        $value = null;
    9496                        if ( strpos( $line, ':' ) === false ) {
    9597                                // Some plugins have line-breaks within the headers.
     
    258260                while ( ( $line = array_shift( $contents ) ) !== null ) {
    259261                        $trimmed = trim( $line );
    260                         if ( ! empty( $line ) ) {
     262                        if ( ! empty( $trimmed ) ) {
    261263                                break;
    262264                        }
     
    343345
    344346        /**
    345          * Sanitize proided contributors to valid WordPress users
     347         * Sanitize provided contributors to valid WordPress users
    346348         *
    347349         * @param array $users Array of user_login's or user_nicename's.
     
    370372                }
    371373                if ( is_null( $markdown ) ) {
    372                         $markdown = new \Michelf\MarkdownExtra();
     374                        $markdown = new MarkdownExtra();
    373375                }
    374376
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r2991 r2994  
    1616                $post = get_post( $post );
    1717
    18                 return get_post_meta( $post->ID, 'active_installs', true );
     18                return (int) get_post_meta( $post->ID, 'active_installs', true );
    1919        }
    2020
     
    149149         *
    150150         * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug.
     151         * @param string          $output Output type. 'html' or 'raw'. Default: 'raw'.
    151152         * @return mixed
    152153         */
     
    218219         *
    219220         * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug.
     221         * @param string          $output Output type. Default: 'raw'.
    220222         * @return mixed
    221223         */
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r2969 r2994  
    4343         * Process an import for a Plugin into the Plugin Directory.
    4444         *
     45         * @throws \Exception
     46         *
    4547         * @param string $plugin_slug The slug of the plugin to import.
    46          * @return void.
    4748         */
    4849        public function import( $plugin_slug ) {
     
    122123         * - Handles readme.md & readme.txt prefering the latter.
    123124         * - Searches for Screenshots in /$stable/ and in /assets/ (listed remotely).
     125         *
     126         * @throws \Exception
    124127         *
    125128         * @param string $plugin_slug The slug of the plugin to parse.
     
    249252                return false;
    250253        }
    251 
    252254}
    253 
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/plugin-directory.php

    r2655 r2994  
    2626
    2727// Instantiate the Plugin Directory
    28 include __DIR__ . '/class-plugin-directory.php';
    2928Plugin_Directory::instance();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r2986 r2994  
    173173                        'tags'        => $readme->tags,
    174174                        'meta'        => array(
    175                                 'stable_tag'          => $readme->stable_tag,
    176175                                'tested'              => $readme->tested,
    177176                                'requires'            => $readme->requires,
     177                                'stable_tag'          => $readme->stable_tag,
     178                                'upgrade_notice'      => $readme->upgrade_notice,
     179                                'contributors'        => $readme->contributors,
     180                                'screenshots'         => $readme->screenshots,
    178181                                'donate_link'         => $readme->donate_link,
     182                                'sections'            => array_keys( $readme->sections ),
    179183                                'version'             => $this->plugin['Version'],
     184                                'header_name'         => $this->plugin['Name'],
    180185                                'header_plugin_uri'   => $this->plugin['PluginURI'],
    181186                                'header_author'       => $this->plugin['Author'],
     
    183188                                'header_textdomain'   => $this->plugin['TextDomain'],
    184189                                'header_description'  => $this->plugin['Description'],
    185                                 'support_threads'     => 0,
     190                                'assets_screenshots'       => array(),
     191                                'assets_icons'             => array(),
     192                                'assets_banners'           => array(),
     193                                'assets_banners_color'     => false,
     194                                'support_threads'          => 0,
    186195                                'support_threads_resolved' => 0,
    187196                        ),
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-filesystem.php

    r2640 r2994  
    4040         * Extract a ZIP file to a directory.
    4141         *
    42          * @param string $zip_file The ZIP file to extract.
    43          * @param string $temp_directory The Directory to extract the ZIP to. Optional. Default: A Temporary directory.
     42         * @param string $zip_file  The ZIP file to extract.
     43         * @param string $directory The Directory to extract the ZIP to. Optional. Default: A Temporary directory.
    4444         *
    4545         * @return string The directory the ZIP was extracted to.
     
    103103         * @param string $dir The directory to remove.
    104104         *
    105          * @return bool Whether the directory was removed..
     105         * @return bool Whether the directory was removed.
    106106         */
    107107        public static function rmdir( $dir ) {
    108                 if ( ! trim( $dir, '/' ) ) {
    109                         return;
     108                if ( trim( $dir, '/' ) ) {
     109                        exec( 'rm -rf ' . escapeshellarg( $dir ) );
    110110                }
    111                 exec( 'rm -rf ' . escapeshellarg( $dir ) );
    112111
    113112                return is_dir( $dir );
    114113        }
    115 
    116114}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php

    r2930 r2994  
    8282                        return $files;
    8383                }
    84 
    85                 return false;
    8684        }
    8785
Note: See TracChangeset for help on using the changeset viewer.