Having two Admin In WordPress

With Following im able to remove the menu if user role is not administrator

add_action('admin_menu', function () {
	if(!current_user_can('administrator')) {
    remove_menu_page('edit-comments.php');
    remove_menu_page('options-general.php');
    remove_menu_page('users.php');
    remove_menu_page('tools.php');
    remove_menu_page('edit.php?post_type=acf-field-group');
    remove_menu_page('plugins.php');
    remove_menu_page('update-core.php');
}
    
});

but what i want is, one admin (like super-admin) having full access to the site and second admin with some limitation like i want remove plugin menu for 2nd admin and give rest access

//2nd admin can be user name or user id
add_action('admin_menu', function () {
	if(current_user_can('administrator' === '2nd admin')) {
  remove_menu_page('users.php');
    remove_menu_page('tools.php');
    remove_menu_page('plugins.php');
   
}
    
});

how can i control / limit few feature for 2nd admin…
or should i create custom role… for the feature i wanted…

got the solution by cloning the administrator

add_action('init', 'newAdmin');

function newAdmin()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();

    $adm = $wp_roles->get_role('administrator');
    
    $wp_roles->add_role('Admin_limit', '2nd Admin', $adm->capabilities);
}
2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.