WordPress.org

Making WordPress.org

Ticket #3202: 3202-new-code.txt

File 3202-new-code.txt, 1.1 KB (added by RMarks, 7 months ago)

This isn't a diff, but should be added to wordcamp's wcorg-misc.php in mu-plugins.

Line 
1function site_admins_can_activate_deactivate_whitelisted_plugins( $allcaps, $caps, $args, $user ) {
2        $current_user = wp_get_current_user();
3        $roles = $current_user->roles;
4        if( 'administrator' != $roles[0] ) {
5                return $allcaps;
6        }
7
8        if( 'activate_plugin' != $args[0] && 'deactivate_plugin' != $args[0] ) {
9                return $allcaps;
10        }
11
12        $whitelisted_plugins = array(
13                'campt-indian-payment-gateway/campt-indian-payment-gateway.php',
14                'camptix-kdcpay-gateway/camptix-kdcpay.php',
15                'camptix-mailchimp/camptix-mailchimp.php',
16                'camptix-mercadopago/camptix-mercadopago.php',
17                'camptix-pagseguro/camptix-pagseguro.php',
18                'camptix-payfast-gateway/camptix-payfast.php',
19                'camptix-trustcard/camptix-trustcard.php',
20                'camptix-trustpay/camptix-trustpay.php',
21                'edit-flow/edit_flow.php',
22                'liveblog/liveblog.php',
23        );
24
25        if( ! in_array( $args[2], $whitelisted_plugins ) ) {
26            $allcaps[ 'activate_plugins' ] = 0;
27            $allcaps[ 'deactivate_plugins' ] = 0;
28        }
29
30        return $allcaps;
31}
32add_filter( 'user_has_cap', __NAMESPACE__ . '\site_admins_can_activate_deactivate_whitelisted_plugins', 10, 4 );