Making WordPress.org


Ignore:
Timestamp:
10/19/2016 02:30:54 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Move the Stats from wp-admin to the front-end /$plugin/admin/ screen.
This also implements the capabilities required for access to the plugin admin screen for each plugin.

See #2111

File:
1 edited

Legend:

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

    r4259 r4260  
    244244            ),
    245245            'public'            => true,
    246             'show_ui'           => is_super_admin(),
     246            'show_ui'           => true,
    247247            'show_admin_column' => false,
    248248            'meta_box_cb'       => false,
     
    286286        add_rewrite_tag( '%browse%', '(featured|popular|beta|new|favorites)' );
    287287        add_permastruct( 'browse', 'browse/%browse%' );
    288 
    289         // /browse/ should be the popular archive view.
    290         add_rewrite_rule( '^browse$', 'index.php?browse=popular', 'top' );
    291288
    292289        // Create an archive for a users favorites too.
     
    570567            }
    571568
    572             // TODO: Make plugins owned by `post_author = $current_user_id` show up here when they're not-publish?
    573 
    574569            $wp_query->query_vars['orderby'] = 'post_title';
    575570            $wp_query->query_vars['order'] = 'ASC';
     
    592587                }
    593588
    594                 // TODO: Switch this to the capabilities systems
     589                // Only the 'publish' cap shouldn't be affected by cap checks.
    595590                $restricted_access_statii = array_diff( $wp_query->query_vars['post_status'], array( 'publish' ) );
    596591                foreach ( $posts as $i => $post ) {
     
    600595                    }
    601596
    602                     // Plugin Reviewers can see all sorts of plugins
    603                     if ( current_user_can( 'plugin_review' ) ) {
     597                    // If the current user can view the plugin admin, show it
     598                    if ( current_user_can( 'plugin_admin_view', $post ) ) {
    604599                        continue;
    605600                    }
    606601
    607                     // Original submitter can always see
    608                     if ( $post->post_author == get_current_user_id() ) {
    609                         continue;
    610                     }
    611 
    612                     // Committers (user_login) can always see
    613                     if ( in_array( wp_get_current_user()->user_login, (array) Tools::get_plugin_committers( $post->post_name ), true ) ) {
    614                         continue;
    615                     }
    616 
    617                     // Contributors (user_nicename) can always see
    618                     if ( in_array( wp_get_current_user()->user_nicename, (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'slug' ), true ) ) {
    619                         continue;
    620                     }
    621 
    622                     // everyone else can't.
     602                    // Else hide it.
    623603                    unset( $posts[ $i ] );
    624604                }
     
    802782            case 'plugin_contributors':
    803783            case 'plugin_committers':
    804                 $user = get_user_by( 'slug', $term->slug );
     784                $user = get_user_by( 'slug', $term->name );
    805785                $name = $user->display_name;
    806786                break;
     
    888868        }
    889869
    890         // TODO: Switch this to the capabilities systems, check if post_author should access
    891870        // Filter access to the plugin administration area. Only certain users are allowed access.
    892         if ( get_query_var( 'plugin_admin' ) && ! current_user_can( 'plugin_review' ) ) {
    893             $post = Plugin_Directory::get_plugin_post( get_query_var( 'name' ) );
    894             if (
    895                 // Logged out users can't access plugin admin
    896                 ! is_user_logged_in() ||
    897                 // Allow access to Committers OR Contributors.
    898                 ! (
    899                     // Committers can access plugin admin
    900                     in_array( wp_get_current_user()->user_login, (array) Tools::get_plugin_committers( $post->post_name ), true ) ||
    901                     // Contributors can access plugin admin (but will have a more limited access)
    902                     in_array( wp_get_current_user()->user_nicename, (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'slug' ), true )
    903                 )
    904             ) {
    905                 wp_safe_redirect( get_permalink( $post ) );
    906                 die();
    907             }
     871        if ( get_query_var( 'plugin_admin' )  &&
     872            ! current_user_can(
     873                'plugin_admin_view',
     874                $post = Plugin_Directory::get_plugin_post( get_query_var( 'name' ) )
     875            )
     876        ) {
     877            wp_safe_redirect( get_permalink( $post ) );
     878            die();
    908879        }
    909880    }
Note: See TracChangeset for help on using the changeset viewer.