Last active
January 9, 2018 03:54
-
-
Save soderlind/8101b2e45e80b594e9c5 to your computer and use it in GitHub Desktop.
Control what (super) admins can do. Works with regular and multisite WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Not So Super Admin | |
Plugin URI: https://gist.github.com/soderlind/8101b2e45e80b594e9c5 | |
Description: Control what (super) admins can do | |
Author: Per Soderlind | |
Author URI: http://soderlind.no | |
Version: 0.0.6 | |
License: GPL | |
Tags: multisite, admin | |
// credit: http://wordpress.stackexchange.com/a/56050/14546 | |
// edit below, save in mu-plugins | |
*/ | |
add_filter( 'map_meta_cap', 'not_so_super_admins', 10, 4 ); | |
function not_so_super_admins( $caps, $cap, $user_id, $args ) { | |
switch ( $user_id ) { | |
// Add/remove user id | |
case 1: | |
case 2: | |
// don't remove capabilities for these user ids | |
break; | |
case 3: | |
if ( in_array( $cap, array( | |
/* WordPress core */ | |
'update_core' // Prevent WordPress core update | |
/* Plugins */ | |
, 'install_plugins' | |
// , 'update_plugins' | |
// , 'delete_plugins' | |
, 'edit_plugins' | |
// , 'activate_plugins' | |
/* Themes */ | |
// , 'install_themes' | |
// , 'update_themes' | |
, 'edit_themes' | |
// , 'delete_themes' | |
/* Multisite only */ | |
// , 'manage_network' // Prevent access to Network Sites menu | |
// , 'manage_network_users' // Prevent access to Network Users menu | |
// , 'manage_network_themes' // Prevent access to Network Themes menu | |
// , 'manage_network_options' // Prevent access to Network Options menu | |
// , 'manage_network_plugins' // Prevent access to Network Plugins menu | |
) ) ) { | |
$caps[] = 'do_not_allow'; | |
} | |
break; | |
default: | |
if ( in_array( $cap, array( | |
/* WordPress core */ | |
'update_core' // Prevent WordPress core update | |
/* Plugins */ | |
// , 'install_plugins' | |
// , 'update_plugins' | |
// , 'delete_plugins' | |
// , 'edit_plugins' | |
// , 'activate_plugins' | |
/* Themes */ | |
// , 'install_themes' | |
// , 'update_themes' | |
// , 'edit_themes' | |
// , 'delete_themes' | |
/* Multisite only */ | |
// , 'manage_network' // Prevent access to Network Sites menu | |
// , 'manage_network_users' // Prevent access to Network Users menu | |
// , 'manage_network_themes' // Prevent access to Network Themes menu | |
// , 'manage_network_options' // Prevent access to Network Options menu | |
// , 'manage_network_plugins' // Prevent access to Network Plugins menu | |
) ) ) { | |
$caps[] = 'do_not_allow'; | |
} | |
break; | |
} | |
return $caps; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment