How to add edit users capability to a custom role?

Here is the code which I added to give ‘edit_users’ capability to a custom role.

function edit_shop_manager() {
    // Get custom role
    $shop_manager = get_role('shop_manager');
    $shop_manager->add_cap('create_users');
    $shop_manager->add_cap('edit_users');
    $shop_manager->add_cap('delete_users');
    $shop_manager->add_cap('list_users');
    $shop_manager->add_cap('remove_users');
    $shop_manager->add_cap('promote_users');
}
add_action( 'init', 'edit_shop_manager' );

When I added this code in functions.php, Users section is visible to the users with role ‘shop_manager’. But edit user option is not available.

Is there something wrong with the code?

1 Answer
1

In the particular case that you were working on a multisite installation. Did you try to also add the ‘manage_network_users’ capability?

function edit_shop_manager() {
    // Get custom role
    $shop_manager = get_role('shop_manager');
    $shop_manager->add_cap('create_users');
    $shop_manager->add_cap('edit_users');
    $shop_manager->add_cap('manage_network_users');
    $shop_manager->add_cap('delete_users');
    $shop_manager->add_cap('list_users');
    $shop_manager->add_cap('remove_users');
    $shop_manager->add_cap('promote_users');
}
add_action( 'init', 'edit_shop_manager' );

Leave a Comment