Hi there – I thought I’d post an update to this issue as it is now resolved and may help other users. The following code snippet will allow Shop Managers to view the users section and edit / delete users again.
/**
* This code snippet restores capabilities 'edit_user' and 'delete_user' if they were blocked by a third-party plugin.
*/
if ( function_exists( 'UM' ) ) {
function um_map_meta_cap( $caps, $cap, $user_id, $args ) {
static $permissions = array();
$index = array_keys( $caps, 'do_not_allow' );
if ( $index ) {
$index = current( $index );
if ( empty( $permissions[$user_id] ) ) {
$role = UM()->roles()->get_priority_user_role( $user_id );
$permissions[$user_id] = UM()->roles()->role_data( $role );
}
$p = $permissions[$user_id];
switch ( $cap ) {
case 'edit_user':
case 'edit_users':
case 'promote_user':
if ( !empty( $p['can_edit_everyone'] ) ) { // role setting Can edit other member accounts?
if ( empty( $p['can_edit_roles'] ) ) {
unset( $caps[$index] );
} elseif ( is_array( $p['can_edit_roles'] ) && isset( $args[0] ) && is_numeric( $args[0] ) ) {
$urole = UM()->roles()->get_priority_user_role( $args[0] );
if ( in_array( $urole, $p['can_edit_roles'] ) ) {
unset( $caps[$index] );
}
}
}
break;
case 'delete_user':
case 'delete_users':
if ( !empty( $p['can_delete_everyone'] ) ) { // role setting Can delete other member accounts?
if ( empty( $p['can_delete_roles'] ) ) {
unset( $caps[$index] );
} elseif ( is_array( $p['can_delete_roles'] ) && isset( $args[0] ) && is_numeric( $args[0] ) ) {
$urole = UM()->roles()->get_priority_user_role( $args[0] );
if ( in_array( $urole, $p['can_delete_roles'] ) ) {
unset( $caps[$index] );
}
}
}
break;
}
}
return $caps;
}
add_filter( 'map_meta_cap', 'um_map_meta_cap', 99, 4 );
}
Bonus snippet: The following snippet will restore the ability for Woocommerce Shop Managers to change user roles when paired with the above snippet.
/**
* Allow Shop Managers to edit and promote users with a specified role
* using the 'woocommerce_shop_manager_editable_roles' filter.
*
* @param array $roles Array of role slugs for users Shop Managers can edit.
* @return array
*/
function myextension_shop_manager_role_edit_capabilities( $roles ) {
$roles[] = 'placeholder_role1';
$roles[] = 'placeholder_role2';
$roles[] = 'placeholder_role3';
return $roles;
}
add_filter( 'woocommerce_shop_manager_editable_roles', 'myextension_shop_manager_role_edit_capabilities' );