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-capabilities.php

    r4212 r4260  
    2222     */
    2323    public static function map_meta_cap( $required_caps, $cap, $user_id, $context ) {
     24        $plugin_edit_cap = false;
    2425        switch( $cap ) {
    25 
    26             // TODO: Map these for the users
    27             case 'plugin_edit':
     26            case 'plugin_admin_edit':
    2827            case 'plugin_add_committer':
    2928            case 'plugin_remove_committer':
     29                $plugin_edit_cap = true;
     30                // Fall through
     31
     32            case 'plugin_admin_view':
     33                // Committers + Contributors.
     34                // If no committers, post_author.
    3035                $required_caps = array();
    3136                $post = get_post( $context[0] );
     37
    3238                if ( ! $post ) {
    3339                    $required_caps[] = 'do_not_allow';
     
    3541                }
    3642
    37                 $user       = new \WP_User( $user_id );
     43                $user = new \WP_User( $user_id );
     44                if ( $user->has_cap( 'plugin_review' ) ) {
     45                    $required_caps[] = 'plugin_review';
     46                    break;
     47                }
     48
     49                // Committers
    3850                $committers = Tools::get_plugin_committers( $post->post_name );
     51                if ( ! $committers && 'publish' === $post->post_status ) {
     52                    // post_author in the event no committers exist (yet?)
     53                    $committers = array( get_user_by( 'ID', $post->post_author )->user_login );
     54                }
    3955
    40                 if ( (int) $post->post_author === $user_id || in_array( $user->user_login, $committers, true ) ) {
    41                     $required_caps[] = 'plugin_edit_own';
     56                if ( in_array( $user->user_login, $committers ) ) {
     57                    $required_caps[] = 'exist'; // All users are allowed to exist, even when they have no role.
     58                    break;
     59                }
    4260
    43                 } else {
    44 
    45                     if ( in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
    46                         $required_caps[] = 'plugin_review';
    47 
    48                     } else {
    49                         $required_caps[] = 'plugin_approve';
     61                if ( ! $plugin_edit_cap ) {
     62                    // Contributors can view, but not edit.
     63                    $contributors = (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'name' );
     64                    if ( in_array( $user->user_nicename, $contributors, true ) ) {
     65                        $required_caps[] = 'exist'; // All users are allowed to exist, even when they have no role.
     66                        break;
    5067                    }
    5168                }
    52                 break;
    5369
    54             // Don't allow any users to alter the post meta for plugins.
    55             case 'add_post_meta':
    56             case 'edit_post_meta':
    57             case 'delete_post_meta':
    58                 $post = get_post( $context );
    59                 if ( $post && 'plugin' == $post->post_type ) {
    60                     $required_caps[] = 'do_not_allow';
    61                 }
     70                // Else;
     71                $required_caps[] = 'do_not_allow';
    6272                break;
    6373
     
    8595        $reviewer = array(
    8696            'read'                 => true,
    87             'plugin_edit_own'      => true,
    8897            'plugin_set_category'  => true,
    89             'plugin_add_committer' => true,
    90             'plugin_edit_others'   => true,
    9198            'moderate_comments'    => true,
    9299            'plugin_edit_pending'  => true,
Note: See TracChangeset for help on using the changeset viewer.