Making WordPress.org


Ignore:
Timestamp:
10/12/2016 01:03:26 PM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Add the first foundations for the front-end admin/plugin-edit screen.

See #2111

File:
1 edited

Legend:

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

    r4214 r4224  
    4646        add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) );
    4747        add_action( 'template_redirect', array( $this, 'prevent_canonical_for_plugins' ), 9 );
    48         add_action( 'template_redirect', array( $this, 'redirect_old_plugin_urls' ) );
     48        add_action( 'template_redirect', array( $this, 'custom_redirects' ) );
    4949        add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
    5050        add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) );
     
    293293        add_rewrite_rule( '^browse/favorites/([^/]+)$', 'index.php?browse=favorites&favorites_user=$matches[1]', 'top' );
    294294
     295        // Handle plugin admin requests
     296        add_rewrite_rule( '^([^/]+)/admin/?$', 'index.php?name=$matches[1]&plugin_admin=1', 'top' );
     297
    295298        // Add duplicate search rule which will be hit before the following old-plugin tab rules
    296299        add_rewrite_rule( '^search/([^/]+)/?$', 'index.php?s=$matches[1]', 'top' );
     
    588591                }
    589592
     593                // TODO: Switch this to the capabilities systems
    590594                $restricted_access_statii = array_diff( $wp_query->query_vars['post_status'], array( 'publish' ) );
    591595                foreach ( $posts as $i => $post ) {
     
    777781        $vars[] = 'favorites_user';
    778782        $vars[] = 'redirect_plugin_tab';
     783        $vars[] = 'plugin_admin';
    779784
    780785        return $vars;
     
    828833
    829834    /**
    830      * Handles a redirect for the old /$plugin/$tab_name/ URLs and search.php
    831      */
    832     function redirect_old_plugin_urls() {
     835     * Handles all the custom redirects needed in the Plugin Directory.
     836     */
     837    function custom_redirects() {
    833838
    834839        // Handle a redirect for /$plugin/$tab_name/ to /$plugin/#$tab_name.
     
    880885            wp_safe_redirect( site_url( '/search/' . urlencode( get_query_var( 's' ) ) . '/' ) );
    881886            die();
     887        }
     888
     889        // TODO: Switch this to the capabilities systems, check if post_author should access
     890        // Filter access to the plugin administration area. Only certain users are allowed access.
     891        if ( get_query_var( 'plugin_admin' ) && ! current_user_can( 'plugin_review' ) ) {
     892            $post = Plugin_Directory::get_plugin_post( get_query_var( 'name' ) );
     893            if (
     894                // Logged out users can't access plugin admin
     895                ! is_user_logged_in() ||
     896                // Allow access to Committers OR Contributors.
     897                ! (
     898                    // Committers can access plugin admin
     899                    in_array( wp_get_current_user()->user_login, (array) Tools::get_plugin_committers( $post->post_name ), true ) ||
     900                    // Contributors can access plugin admin (but will have a more limited access)
     901                    in_array( wp_get_current_user()->user_nicename, (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'slug' ), true )
     902                )
     903            ) {
     904                wp_safe_redirect( get_permalink( $post ) );
     905                die();
     906            }
    882907        }
    883908    }
Note: See TracChangeset for help on using the changeset viewer.