Making WordPress.org

Changeset 3095


Ignore:
Timestamp:
05/06/2016 10:17:09 PM (9 years ago)
Author:
obenland
Message:

Plugin Directory: Show banners to provide a clearer status for plugins.

Redirects users who can edit a particular plugin that is closed or disabled
from the front-end to the edit page of that plugin and adds admin notices to
give more context about the current status of a plugin.

Fixes #1689.

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

Legend:

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

    r3093 r3095  
    2525     */
    2626    private function __construct() {
     27        add_filter( 'dashboard_glance_items', array( $this, 'plugin_glance_items' ) );
     28
     29        add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
     30        add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ) );
     31
     32        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
     33        add_filter( 'admin_head-edit.php', array( $this, 'plugin_posts_list_table' ) );
     34        add_action( 'admin_notices', array( $this, 'add_post_status_notice' ) );
     35        add_action( 'all_admin_notices', array( $this, 'admin_notices' ) );
     36        add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 );
     37
     38        add_action( 'wp_ajax_replyto-comment', array( $this, 'save_custom_comment' ), 0 );
     39        add_filter( 'comment_row_actions', array( $this, 'custom_comment_row_actions' ), 10, 2 );
     40
    2741        // Admin Metaboxes
    2842        add_action( 'add_meta_boxes', array( $this, 'register_admin_metaboxes' ), 10, 2 );
    2943        add_action( 'do_meta_boxes', array( $this, 'replace_title_global' ) );
    30         add_filter( 'dashboard_glance_items', array( $this, 'plugin_glance_items' ) );
    31 
    32         add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
    33         add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ) );
    34 
    35         add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
    36         add_filter( 'admin_head-edit.php', array( $this, 'plugin_posts_list_table' ) );
    37         add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 );
    38 
    39         add_action( 'wp_ajax_replyto-comment', array( $this, 'save_custom_comment' ), 0 );
    40         add_filter( 'comment_row_actions', array( $this, 'custom_comment_row_actions' ), 10, 2 );
    4144
    4245        add_filter( 'postbox_classes_plugin_internal-notes',    array( __NAMESPACE__ . '\Metabox\Internal_Notes', 'postbox_classes' ) );
     
    221224            $wp_list_table->prepare_items();
    222225        }
     226    }
     227
     228    /**
     229     * Adds banners to provide a clearer status for a plugin.
     230     *
     231     * This is being displayed in the edit screen for a particular plugin,
     232     * providing more context about the current status of a plugin for both
     233     * Committers and Reviewers/Admins.
     234     */
     235    public function add_post_status_notice() {
     236        if ( 'post.php' !== $GLOBALS['pagenow'] ) {
     237            return;
     238        }
     239
     240        $message  = '';
     241        $post     = get_post();
     242        $is_admin = current_user_can( 'plugin_approve' );
     243
     244        switch ( $post->post_status ) {
     245            case 'draft':
     246            case 'pending':
     247                $message = __( 'This plugin is requested and not visible to the public yet.', 'wporg-plugins' );
     248                if ( ! $is_admin ) {
     249                    $message .= ' ' . __( 'Please be patient as your plugin gets reviewed.', 'wporg-plugins' );
     250                }
     251                break;
     252
     253            case 'rejected':
     254                $message = __( 'This plugin is rejected and is not visible to the public.', 'wporg-plugins' );
     255                break;
     256
     257            case 'approved':
     258                $message = __( 'This plugin is approved and awaiting data upload but not visible to the public yet.', 'wporg-plugins' );
     259                if ( ! $is_admin ) {
     260                    $message .= ' ' . __( 'Once you make your first commit, the plugin will become public.', 'wporg-plugins' );
     261                }
     262                break;
     263
     264            case 'closed':
     265                $message = __( 'This plugin is closed and is not visible to the public.', 'wporg-plugins' );
     266                break;
     267
     268            case 'disabled':
     269                $message = __( 'This plugin is closed and is not visible to the public.', 'wporg-plugins' );
     270                if ( $is_admin ) {
     271                    $message = __( 'This plugin is disabled (closed, but actively serving updates) and is not visible to the public.', 'wporg-plugins' );
     272                }
     273                break;
     274        }
     275
     276        if ( $message ) {
     277            add_settings_error( 'wporg-plugins', 'status-notice', $message, 'updated' );
     278        }
     279    }
     280
     281    /**
     282     * Displays all admin notices registered to `wporg-plugins`.
     283     */
     284    public function admin_notices() {
     285        settings_errors( 'wporg-plugins' );
    223286    }
    224287
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3084 r3095  
    2929        add_filter( 'rest_api_allowed_post_types', array( $this, 'filter_allowed_post_types' ) );
    3030        add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) );
    31 
    32         add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 );
     31        add_action( 'template_redirect', array( $this, 'redirect_hidden_plugins' ) );
    3332
    3433        // Shim in postmeta support for data which doesn't yet live in postmeta
    3534        add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );
     35
     36        add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 );
    3637
    3738        // Load the API routes
     
    434435    }
    435436
     437    /**
     438     * Redirects Committers and Admins to a plugin's edit page if it's disabled or closed.
     439     */
     440    public function redirect_hidden_plugins() {
     441        if ( ! is_404() ) {
     442            return;
     443        }
     444
     445        $post = self::get_plugin_post( get_query_var( 'name', false ) );
     446
     447        if ( $post instanceof \WP_Post && in_array( $post->post_status, array( 'disabled', 'closed' ), true ) && current_user_can( 'edit_post', $post ) ) {
     448            wp_safe_redirect( add_query_arg( array( 'post' => $post->ID, 'action' => 'edit' ), admin_url( 'post.php' ) ) );
     449        }
     450    }
    436451
    437452    /**
Note: See TracChangeset for help on using the changeset viewer.