Making WordPress.org


Ignore:
Timestamp:
06/29/2017 12:40:41 AM (9 years ago)
Author:
coreymckrill
Message:

WordCamp Subroles: Add 'jetpack_connector' subrole

This subrole allows the user to manage Jetpack connections
for sites in the network.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-subroles.php

    r5544 r5600  
    2424
    2525        return array();
     26}
     27
     28/**
     29 * Check if a particular user has a particular subrole.
     30 *
     31 * @param int    $user_id The ID of the user to check for a subrole.
     32 * @param string $subrole The subrole to check for.
     33 *
     34 * @return bool True if the user has the subrole.
     35 */
     36function has_subrole( $user_id, $subrole ) {
     37        $subroles = get_user_subroles( $user_id );
     38
     39        return in_array( $subrole, $subroles, true );
    2640}
    2741
    … …  
    5670               
    5771                switch ( $subrole ) {
     72                        case 'jetpack_connector' :
     73                                $newcaps = array(
     74                                        'manage_network'             => true, // Access to network admin.
     75                                        'jetpack_connect'            => true,
     76                                        'jetpack_reconnect'          => true,
     77                                        'jetpack_disconnect'         => true,
     78                                        'jetpack_network_admin_page' => true,
     79                                        'jetpack_network_sites_page' => true,
     80                                );
     81                                break;
     82
    5883                        case 'mentor_manager' :
    5984                                // These capabilities only apply on central.wordcamp.org.
    … …  
    112137                        }
    113138                        break;
     139
     140                // Allow Jetpack Connectors to do connector stuff without needing caps like `manage_network_plugins`.
     141                // See Jetpack::jetpack_custom_caps()
     142                case 'jetpack_connect':
     143                case 'jetpack_reconnect':
     144                case 'jetpack_disconnect':
     145                case 'jetpack_network_admin_page':
     146                case 'jetpack_network_sites_page':
     147                        if ( has_subrole( get_current_user_id(), 'jetpack_connector' ) ) {
     148                                $required_caps[] = $meta_cap;
     149                        }
     150                        break;
    114151        }
    115152
Note: See TracChangeset for help on using the changeset viewer.