What can I add to this code? ... I need to forbid or deny this custom administrator role from creating other administrator user role? thank you

add_action('init', 'cloneRole');

function cloneRole() {
 $adm = get_role('administrator');
 $adm_cap= array_keys( $adm->capabilities ); //get administator capabilities
 add_role('new_role', 'My Custom Role'); //create new role
 $new_role = get_role('new_role');
  foreach ( $adm_cap as $cap ) {
   $new_role->add_cap( $cap ); //clone administrator capabilities to new role
  • Does the user have to be able to create new users of other roles (non-admin)? If not, deny it the "create_users" (if ( 'create_users' != $cap ) {...) capability (possibly also limiting "promote_users" capability). – butlerblog Oct 22 '19 at 17:25

Your Answer

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

Browse other questions tagged or ask your own question.