WordPress.org

Making WordPress.org

Changeset 8013


Ignore:
Timestamp:
12/26/2018 08:21:08 PM (4 months ago)
Author:
iandunn
Message:

WordCamp Misc: Allow site admins to activate optional plugins.

Fixes #3202.
Props RMarks for the initial patch.

File:
1 edited

Legend:

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

    r7939 r8013  
    543543}
    544544
     545/**
     546 * Allow individual site administrators to activate and deactivate optional plugins.
     547 *
     548 * @param array  $required_capabilities The primitive capabilities that are required to perform the requested meta
     549 *                                      capability.
     550 * @param string $requested_capability  The requested meta capability.
     551 * @param int    $user_id               The user ID.
     552 * @param array  $args                  Optional data for the given capability. In this case, the plugin slug to
     553 *                                      activate/deactivate.
     554 *
     555 * @return array The primitive capabilities that are required to perform the requested meta capability.
     556 */
     557function wcorg_let_admins_activate_some_plugins( $required_capabilities, $requested_capability, $user_id, $args ) {
     558    $target_plugin    = $args[0] ?? null;
     559    $optional_plugins = array(
     560        'campt-indian-payment-gateway/campt-indian-payment-gateway.php',
     561        'camptix-kdcpay-gateway/camptix-kdcpay.php',
     562        'camptix-mailchimp/camptix-mailchimp.php',
     563        'camptix-mercadopago/camptix-mercadopago.php',
     564        'camptix-pagseguro/camptix-pagseguro.php',
     565        'camptix-payfast-gateway/camptix-payfast.php',
     566        'camptix-trustcard/camptix-trustcard.php',
     567        'camptix-trustpay/camptix-trustpay.php',
     568        'edit-flow/edit_flow.php',
     569        'liveblog/liveblog.php',
     570    );
     571
     572    switch ( $requested_capability ) {
     573        // Let regular admins visit the Plugins screen.
     574        case 'activate_plugins':
     575        case 'deactivate_plugins':
     576            $required_capabilities = array( 'manage_options' );
     577            break;
     578
     579        // Let regular admins toggle specific plugins on/off.
     580        case 'activate_plugin':
     581        case 'deactivate_plugin':
     582            if ( in_array( $target_plugin, $optional_plugins, true ) ) {
     583                $required_capabilities = array( 'manage_options' );
     584            }
     585            break;
     586    }
     587
     588    return $required_capabilities;
     589}
     590add_filter( 'map_meta_cap', 'wcorg_let_admins_activate_some_plugins', 10, 4 );
Note: See TracChangeset for help on using the changeset viewer.