Making WordPress.org

Changeset 2655


Ignore:
Timestamp:
03/01/2016 07:51:16 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Add several metaboxes for the Plugin Review/Admin.
This change includes switching to custom taxonomies, a custom publish metabox, a custom tags metabox, and the start of a plugin-reviewer metabox.

See #1570, #1584

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

Legend:

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

    r2639 r2655  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin;
     3use \WordPressdotorg\Plugin_Directory;
    34
    45/**
     
    1011
    1112    /**
    12      * Fetch the instance of the Plugin_Directory class.
     13     * Fetch the instance of the Admin Customizations class.
    1314     */
    1415    public static function instance() {
     
    1819    }
    1920
     21    private function __construct() {
     22        // Admin Metaboxes
     23        add_action( 'add_meta_boxes', array( $this, 'register_admin_metaboxes' ), 10, 1 );
     24        add_action( 'do_meta_boxes', array( $this, 'replace_title_global' ) );
     25
     26        add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ), 10, 2 );
     27
     28        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
     29    }
     30
    2031    /**
     32     * Adds the plugin name into the post editing title.
    2133     *
     34     * @global $title The wp-admin title variable.
     35     *
     36     * @param string $post_type The post type of the current page
     37     * @return void.
    2238     */
    23     private function __construct() {
    24         add_action( 'add_meta_boxes', array( $this, 'register_admin_metaboxes' ) );
    25         add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ) );
     39    public function replace_title_global( $post_type ) {
     40        global $title;
     41        if ( 'plugin' === $post_type ) {
     42            $title = sprintf( $title, get_the_title() ); // esc_html() on output
     43        }
     44    }
     45
     46    /**
     47     * Enqueue JS and CSS assets needed for any wp-admin screens.
     48     *
     49     * @param string $hook_suffix The hook suffix of the current screen.
     50     * @return void.
     51     */
     52    public function enqueue_assets( $hook_suffix ) {
     53        global $post_type;
     54
     55        if ( 'post.php' == $hook_suffix && 'plugin' == $post_type ) {
     56            wp_enqueue_style( 'plugin-admin-edit-css', plugins_url( 'css/edit-form.css', Plugin_Directory\PLUGIN_FILE ), array( 'edit' ), 1 );
     57            wp_enqueue_script( 'plugin-admin-edit-js', plugins_url( 'js/edit-form.js', Plugin_Directory\PLUGIN_FILE ), array(), 1 );
     58        }
    2659    }
    2760
    2861    /**
    2962     * Register the Admin metaboxes for the plugin management screens.
     63     *
     64     * @param string $post_type The post type of the current screen.
     65     * @return void.
    3066     */
    31     public function register_admin_metaboxes() {
     67    public function register_admin_metaboxes( $post_type ) {
     68        if ( 'plugin' != $post_type ) {
     69            return;
     70        }
     71
    3272        add_meta_box(
    3373            'plugin-committers',
    3474            __( 'Plugin Committers', 'wporg-plugins' ),
    35             array( __NAMESPACE__ . '\\Metabox\\Committers', 'display' ),
    36             'plugin'
     75            array( __NAMESPACE__ . '\Metabox\Committers', 'display' ),
     76            'plugin', 'side'
    3777        );
     78
     79        add_meta_box(
     80            'plugin-review',
     81            __( 'Plugin Review Tools', 'wporg-plugins' ),
     82            array( __NAMESPACE__ . '\Metabox\Review_Tools', 'display' ),
     83            'plugin', 'normal', 'high'
     84        );
     85
     86        add_meta_box(
     87            'plugin-fields',
     88            __( 'Plugin Meta', 'wporg-plugins' ),
     89            array( __NAMESPACE__ . '\Metabox\Custom_Fields', 'display' ),
     90            'plugin', 'normal', 'low'
     91        );
     92
     93        // Replace the publish box
     94        add_meta_box(
     95            'submitdiv',
     96            __( 'Plugin Controls', 'wporg-plugins' ),
     97            array( __NAMESPACE__ . '\Metabox\Controls', 'display' ),
     98            'plugin', 'side', 'high'
     99        );
     100
     101        // Remove the Slug metabox
     102        add_meta_box( 'slugdiv', false, false, false );
    38103    }
    39104
    40105    /**
    41      * Displays a link to the plugins zip file.
     106     * Hook into the save process for the plugin post_type to save extra metadata.
    42107     *
    43      * @param \WP_Post $post
     108     * Currently saves the tested_with value.
     109     *
     110     * @param int      $post_id The post_id being updated.
     111     * @param \WP_Post $post    The WP_Post object being updated.
    44112     */
    45     public function edit_form_after_title( $post ) {
    46         $zip_files = get_attached_media( 'application/zip', $post );
    47         $zip_file  = current( $zip_files );
    48         $zip_url   = wp_get_attachment_url( $zip_file->ID );
     113    public function save_plugin_post( $post_id, $post ) {
     114        // Save meta information
     115        if ( isset( $_POST['tested_with'] ) && isset( $_POST['hidden_tested_with'] ) && $_POST['tested_with'] != $_POST['hidden_tested_with'] ) {
     116            update_post_meta( $post_id, 'tested', wp_slash( wp_unslash( $_POST['tested_with'] ) ) );
     117        }
     118    }
    49119
    50         if ( $zip_url ) :
    51             ?>
    52 
    53             <p style="padding: 0 10px;">
    54                 <?php printf( __( '<strong>Zip file:</strong> %s' ), sprintf( '<a href="%s">%s</a>', esc_url( $zip_url ), esc_html( $zip_url ) ) ); ?>
    55             </p>
    56 
    57         <?php
    58         endif;
    59     }
    60120}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php

    r2621 r2655  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
    3 
    43use WordPressdotorg\Plugin_Directory\Tools;
    54
     
    109 */
    1110class Committers {
    12 
    13     /**
    14      *
    15      */
    1611    static function display() {
    1712        $plugin_slug         = get_post()->post_name;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r2640 r2655  
    1212     * Fetch the instance of the Plugin_Directory class.
    1313     */
    14     public static function instance( $plugin_file = null ) {
     14    public static function instance() {
    1515        static $instance = null;
    1616
    17         return ! is_null( $instance ) ? $instance : $instance = new Plugin_Directory( $plugin_file );
    18     }
    19 
    20     /**
    21      * @param string $plugin_file
    22      */
    23     private function __construct( $plugin_file ) {
     17        return ! is_null( $instance ) ? $instance : $instance = new Plugin_Directory();
     18    }
     19
     20    private function __construct() {
    2421        add_action( 'init', array( $this, 'init' ) );
    2522        add_action( 'init', array( $this, 'register_shortcodes' ) );
     
    3027
    3128        // Load all Admin-specific items.
    32         add_action( 'admin_init', array( __NAMESPACE__ . '\\Admin\\Customizations', 'instance' ) );
    33 
    34         register_activation_hook( $plugin_file, array( $this, 'activate' ) );
    35         register_deactivation_hook( $plugin_file, array( $this, 'deactivate' ) );
     29        add_action( 'admin_init', array( __NAMESPACE__ . '\Admin\Customizations', 'instance' ) );
     30
     31        register_activation_hook( PLUGIN_FILE, array( $this, 'activate' ) );
     32        register_deactivation_hook( PLUGIN_FILE, array( $this, 'deactivate' ) );
    3633    }
    3734
     
    4340
    4441        register_post_type( 'plugin', array(
    45             'labels'      => array(
    46                 'name'               => __( 'Plugins',          'wporg-plugins' ),
    47                 'singular_name'      => __( 'Plugin',           'wporg-plugins' ),
    48                 'menu_name'          => __( 'My Plugins',       'wporg-plugins' ),
    49                 'add_new'            => __( 'Add New',          'wporg-plugins' ),
    50                 'add_new_item'       => __( 'Add New Plugin',   'wporg-plugins' ),
    51                 'edit_item'          => __( 'Edit Plugin',      'wporg-plugins' ),
    52                 'new_item'           => __( 'New Plugin',       'wporg-plugins' ),
    53                 'view_item'          => __( 'View Plugin',      'wporg-plugins' ),
    54                 'search_items'       => __( 'Search Plugins',   'wporg-plugins' ),
    55                 'not_found'          => __( 'No plugins found', 'wporg-plugins' ),
     42            'labels'          => array(
     43                'name'               => __( 'Plugins',                   'wporg-plugins' ),
     44                'singular_name'      => __( 'Plugin',                    'wporg-plugins' ),
     45                'menu_name'          => __( 'My Plugins',                'wporg-plugins' ),
     46                'add_new'            => __( 'Add New',                   'wporg-plugins' ),
     47                'add_new_item'       => __( 'Add New Plugin',            'wporg-plugins' ),
     48                'edit_item'          => __( 'Editing Plugin: %s',        'wporg-plugins' ),
     49                'new_item'           => __( 'New Plugin',                'wporg-plugins' ),
     50                'view_item'          => __( 'View Plugin',               'wporg-plugins' ),
     51                'search_items'       => __( 'Search Plugins',            'wporg-plugins' ),
     52                'not_found'          => __( 'No plugins found',          'wporg-plugins' ),
    5653                'not_found_in_trash' => __( 'No plugins found in Trash', 'wporg-plugins' ),
    5754            ),
    58             'description' => __( 'A Repo Plugin', 'wporg-plugins' ),
    59             'supports'    => array( 'title', 'editor', 'excerpt', 'custom-fields' ),
    60             'taxonomies'  => array( 'post_tag', 'category' ),
    61             'public'      => true,
    62             'show_ui'     => true,
    63             'has_archive' => true,
    64             'rewrite'     => false,
    65             'menu_icon'   => 'dashicons-admin-plugins',
     55            'description'     => __( 'A Repo Plugin', 'wporg-plugins' ),
     56            'supports'        => false,
     57            'public'          => true,
     58            'show_ui'         => true,
     59            'has_archive'     => true,
     60            'rewrite'         => false,
     61            'menu_icon'       => 'dashicons-admin-plugins',
     62            'capability_type' => array( 'post', 'posts' ), // TODO roles & capabilities
     63            'map_meta_cap'    => true,
     64            'capabilities'    => array(
     65                'create_posts' => 'do_not_allow'
     66            )
     67        ) );
     68
     69        register_taxonomy( 'plugin_category', 'plugin', array(
     70            'hierarchical'      => true,
     71            'query_var'         => 'plugin_category',
     72            'rewrite'           => false,
     73            'public'            => true,
     74            'show_ui'           => true,
     75            'show_admin_column' => true,
     76            'meta_box_cb'       => 'post_categories_meta_box',
     77            'capabilities'      => array(
     78                'assign_terms' => 'manage_categories',
     79            )
     80        ) );
     81
     82        register_taxonomy( 'plugin_tag', 'plugin', array(
     83            'hierarchical'      => true, /* for tax_input[] handling on post saves. */
     84            'query_var'         => 'plugin_tag',
     85            'rewrite'           => array(
     86                'hierarchical' => false,
     87                'slug'         => 'tags',
     88                'with_front'   => false,
     89                'ep_mask'      => EP_TAGS,
     90            ),
     91            'labels'            => array(
     92                'name'          => __( 'Plugin Tags',  'wporg-plugins' ),
     93                'singular_name' => __( 'Plugin Tag',   'wporg-plugins' ),
     94                'edit_item'     => __( 'Edit Tag',     'wporg-plugins' ),
     95                'update_item'   => __( 'Update Tag',   'wporg-plugins' ),
     96                'add_new_item'  => __( 'Add New Tag',  'wporg-plugins' ),
     97                'new_item_name' => __( 'New Tag Name', 'wporg-plugins' ),
     98                'search_items'  => __( 'Search Tags',  'wporg-plugins' ),
     99            ),
     100            'public'            => true,
     101            'show_ui'           => true,
     102            'show_admin_column' => true,
     103            'meta_box_cb'       => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Tags', 'display' ),
     104            'capabilities'      => array()
    66105        ) );
    67106
     
    83122            'show_in_admin_status_list' => true,
    84123            'label_count'               => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'wporg-plugins' ),
     124        ) );
     125        register_post_status( 'rejected', array(
     126            'label'                     => _x( 'Rejected', 'plugin status', 'wporg-plugins' ),
     127            'public'                    => false,
     128            'show_in_admin_status_list' => true,
     129            'label_count'               => _n_noop( 'Rejected <span class="count">(%s)</span>', 'Rejected <span class="count">(%s)</span>', 'wporg-plugins' ),
    85130        ) );
    86131
     
    108153     */
    109154    public function register_shortcodes() {
    110         add_shortcode( 'wporg-plugin-upload',       array( __NAMESPACE__ . '\\Shortcodes\\Upload',      'display' ) );
    111         add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\\Shortcodes\\Screenshots', 'display' ) );
    112     //  add_shortcode( 'wporg-plugins-stats',       array( __NAMESPACE__ . '\\Shortcodes\\Stats',       'display' ) );
    113     //  add_shortcode( 'wporg-plugins-developer',   array( __NAMESPACE__ . '\\Shortcodes\\Developer',   'display' ) );
    114     }
    115 
    116     /**
     155        add_shortcode( 'wporg-plugin-upload',       array( __NAMESPACE__ . '\Shortcodes\Upload',      'display' ) );
     156        add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\Shortcodes\Screenshots', 'display' ) );
     157    //  add_shortcode( 'wporg-plugins-stats',       array( __NAMESPACE__ . '\Shortcodes\Stats',       'display' ) );
     158    //  add_shortcode( 'wporg-plugins-developer',   array( __NAMESPACE__ . '\Shortcodes\Developer',   'display' ) );
     159    }
     160
     161    /**
     162     * Upon plugin activation, set up the current site for acting
     163     * as the plugin directory.
     164     *
     165     * Setting up the site requires setting up the theme and proper
     166     * rewrite permastructs.
     167     *
    117168     * @global \WP_Rewrite $wp_rewrite WordPress rewrite component.
    118169     */
     
    148199
    149200    /**
    150      *
     201     * Clean up options & rewrite rules after plugin deactivation.
    151202     */
    152203    public function deactivate() {
     
    241292        switch ( get_query_var( 'browse' ) ) {
    242293            case 'beta':
    243                 $wp_query->query_vars['category_name'] = 'beta';
     294                $wp_query->query_vars['plugin_category'] = 'beta';
    244295                break;
    245296
    246297            case 'featured':
    247                 $wp_query->query_vars['category_name'] = 'featured';
     298                $wp_query->query_vars['plugin_category'] = 'featured';
    248299                break;
    249300
     
    326377     *
    327378     * @param $plugin_slug string|\WP_Post The slug of the plugin to retrieve.
    328      * @return \WP_Post|\WP_Error
     379     * @return \WP_Post|bool
    329380     */
    330381    static public function get_plugin_post( $plugin_slug ) {
     382        global $post;
    331383        if ( $plugin_slug instanceof \WP_Post ) {
    332384            return $plugin_slug;
     385        }
     386        // Use the global $post object when it matches to avoid hitting the database.
     387        if ( !empty( $post ) && 'plugin' == $post->post_type && $plugin_slug == $post->post_name ) {
     388            return $post;
    333389        }
    334390
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r2649 r2655  
    33use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    44use WordPressdotorg\Plugin_Directory\Readme_Parser;
     5use WordPressdotorg\Plugin_Directory\Template;
    56use WordPressdotorg\Plugin_Directory\Tools;
    67use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
     
    8889
    8990        foreach ( $this->readme_fields as $readme_field ) {
    90             update_post_meta( $plugin->ID, $readme_field, $readme->$readme_field );
     91            // Don't change the tested version if a newer version was specified through wp-admin
     92            if ( 'tested' == $readme_field && version_compare( get_post_meta( $plugin->ID, 'tested', true ), $readme->$readme_field, '>' ) ) {
     93                continue;
     94            }
     95            update_post_meta( $plugin->ID, $readme_field, wp_slash( $readme->$readme_field ) );
    9196        }
    9297        foreach ( $this->plugin_headers as $plugin_header => $meta_field ) {
    93             update_post_meta( $plugin->ID, $meta_field, $headers->$plugin_header );
     98            update_post_meta( $plugin->ID, $meta_field, wp_slash( $headers->$plugin_header ) );
    9499        }
    95100
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/plugin-directory.php

    r2621 r2655  
    1616namespace WordPressdotorg\Plugin_Directory;
    1717
     18/**
     19 * Store the root plugin file for usage with functions which use the plugin basename.
     20 */
     21define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ );
     22
    1823// Register an Autoloader for all files
    1924include __DIR__ . '/class-autoloader.php';
    2025Autoloader\register_class_path( __NAMESPACE__, __DIR__ );
    2126
    22 // Create the instance of the plugin, passing __FILE__ for actions that need it.
     27// Instantiate the Plugin Directory
    2328include __DIR__ . '/class-plugin-directory.php';
    24 Plugin_Directory::instance( __FILE__ );
     29Plugin_Directory::instance();
Note: See TracChangeset for help on using the changeset viewer.