WordPress.org

Make WordPress Core

Changeset 40390


Ignore:
Timestamp:
04/07/17 12:52:24 (6 months ago)
Author:
flixos90
Message:

Multisite: Introduce a setup_network capability for setting up multisite.

setup_network is a new meta capability that brings more granular control over the permissions to setup a multisite environment. In a non-multisite environment it falls back to manage_options while in a multisite it falls back to manage_network_options. The introduction of this capability furthermore allows replacing an is_super_admin() check.

Props ashokkumar24 for the original patch.
Fixes #39206. See #37616.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/menu.php

    r40313 r40390  
    245245        $submenu['tools.php'][25] = array( __('Delete Site'), 'delete_site', 'ms-delete-site.php' ); 
    246246    if ( ! is_multisite() && defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE ) 
    247         $submenu['tools.php'][50] = array(__('Network Setup'), 'manage_options', 'network.php'); 
     247        $submenu['tools.php'][50] = array(__('Network Setup'), 'setup_network', 'network.php'); 
    248248 
    249249$menu[80] = array( __('Settings'), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' ); 
  • trunk/src/wp-admin/network.php

    r39019 r40390  
    1616require_once( dirname( __FILE__ ) . '/admin.php' ); 
    1717 
    18 if ( ! is_super_admin() ) { 
     18if ( ! current_user_can( 'setup_network' ) ) { 
    1919    wp_die( __( 'Sorry, you are not allowed to manage options for this site.' ) ); 
    2020} 
  • trunk/src/wp-admin/network/menu.php

    r38827 r40390  
    5454if ( defined( 'MULTISITE' ) && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) { 
    5555    $submenu['settings.php'][5]  = array( __('Network Settings'), 'manage_network_options', 'settings.php' ); 
    56     $submenu['settings.php'][10] = array( __('Network Setup'), 'manage_network_options', 'setup.php' ); 
     56    $submenu['settings.php'][10] = array( __('Network Setup'), 'setup_network', 'setup.php' ); 
    5757} 
    5858unset($update_data); 
  • trunk/src/wp-includes/capabilities.php

    r39588 r40390  
    481481        $caps[] = $cap; 
    482482        break; 
     483    case 'setup_network': 
     484        if ( is_multisite() ) { 
     485            $caps[] = 'manage_network_options'; 
     486        } else { 
     487            $caps[] = 'manage_options'; 
     488        } 
     489        break; 
    483490    default: 
    484491        // Handle meta capabilities for custom post types. 
  • trunk/tests/phpunit/tests/user/capabilities.php

    r39588 r40390  
    228228            'delete_site'            => array(), 
    229229 
     230            'setup_network'          => array( 'administrator' ), 
    230231            'upload_plugins'         => array( 'administrator' ), 
    231232            'upload_themes'          => array( 'administrator' ), 
     
    255256            'manage_network_themes'  => array(), 
    256257            'manage_network_options' => array(), 
     258            'setup_network'          => array(), 
    257259            'upload_plugins'         => array(), 
    258260            'upload_themes'          => array(), 
Note: See TracChangeset for help on using the changeset viewer.