0

I need to make that administrator could'nt manage options, but it is not working...

My code:

function set_capabilities() {
     $editor = get_role( 'administrator' );
     $editor = remove_cap('manage_options');
}
add_action( 'admin_init', 'set_capabilities' );

What I do wrong ?

2 Answers 2

1

you're creating a function and just initializing a local scope variable that you overwrite it.

here is a different approach:

global $wp_roles; // global class wp-includes/capabilities.php
$wp_roles->remove_cap( 'administrator', 'manage_options' );

_based on codex:remove_cap_

Edit:

/**
* Remove capability from admins.
*/
function wpcodex_set_capabilities() {

    // Get the role object.
    $admin = get_role( 'administrator' );
    $admin->remove_cap( 'manage_options' );
}
add_action( 'init', 'wpcodex_set_capabilities' );
3
  • I tried to do this, but not working...
    – andys
    Commented Feb 12, 2014 at 15:40
  • try my later edit Commented Feb 12, 2014 at 16:02
  • I was logged as super admin, so it wasnt working ... now it works fine :)
    – andys
    Commented Feb 12, 2014 at 16:16
1

There's 2 different ways you can do this:

Add either of these code snippets to your child themes functions file.

function set_capabilities() {
     $role = get_role( 'administrator' );
     $role = remove_cap('manage_options');
}
add_action( 'init', 'set_capabilities' );

Or you could also use this:

function set_admin_capabilities(){

global $wp_roles;
$wp_roles->remove_cap( 'administrator', 'manage_options' );
    }
add_action( 'init', 'set_admin_capabilities' );
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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