0

I've created two administrator users X and Y. And now I need to remove capability of 'edit_plugins' from user Y.

I've searched and found, http://goo.gl/LttuvX

$user = new WP_User( 'Y' );
$user->remove_cap('edit_plugins');

But it is not working please let me know how to do it.

Previously I've created new role with same capability as administrator, but in plugins we create menus like add_menu_page(..,capability => 'administrator',..); so new role fails to access plugin pages.

  • The new role method will work, just feed your add_XXX_page calls to use a capability instead of a role, eg. manage_options. – t31os Feb 3 '14 at 17:06
  • Could you specify it in detail? – user1746018 Feb 4 '14 at 3:41
1

If you want to specifically deny a capability from a user (not a role), you need to use the add_cap() method and specify that the $grant parameter is false.

$user = new WP_User( 'Y' );
$user->add_cap( 'edit_plugins', false );
0

Try this by replacing the user@email.com

add_action('init', 'remove_specific_admin_cap');
function remove_specific_admin_cap(){
$user = wp_get_current_user();
if( $user && isset($user->user_email) && 'user@email.com' == $user->user_email ) {
$role = get_role( 'administrator' );
$role->remove_cap( 'edit_plugins' );

    }
}

Source http://codex.wordpress.org/Function_Reference/remove_cap

  • your solution restricting all administrators. So I added, else{ $role = get_role( 'administrator' ); $role->add_cap( 'edit_plugins' ); } it works but I need to refresh page twice. – user1746018 Feb 3 '14 at 12:42
0

Direct editing of Themes/Plugins should never be enabled and is a huge security risk. Any editing you do should be done locally.

You can disable it by adding define('DISALLOW_FILE_EDIT', true); to your wp-config.php file.

If you do not want them messing with plugins, then remove_cap( 'install_plugins' ); or remove_cap( 'activate_plugins' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.