Making WordPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.