0

I have this code in admin_init action

$role = get_role('New_Role');
if(!$role){
    add_role( 'New_Role', 'New Role', array( 'new_cap' => true ) );
}

In user profile everything looks fine in User Roles till I save user with checked New Role. The result is

  1. The role of the user is still not checked, like he doesn't have this role
  2. The new section appears "Additional Capabilities: Capabilities new_role"

Note that Capability is NOT new_cap BUT new_role.

What am I doing wrong?

1 Answer 1

0

Finally found an issue. Something in WP saved role but could not compared correctly and couldn't find correct capabilities.

This code worked as it should (note the case):

$role = get_role('new_role');
if(!$role){
    add_role( 'new_role', 'New Role', array( 'new_cap' => true ) );
}

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.