Change WordPress user roles and capabilities Forums Bug Reports Update 4.48 – User role only customer on Multisites Reply To: Update 4.48 – User role only customer on Multisites

#5194
Vladimir
Keymaster

There is one more function at the same file, which may prevent superadmin from editing users without ‘Customer’ role:


function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
	switch ( $cap ) {
		case 'edit_user':
		case 'remove_user':
		case 'promote_user':
		case 'delete_user':
			if ( ! isset( $args[0] ) || $args[0] === $user_id ) {
				break;
			} else {
				if ( user_can( $args[0], 'administrator' ) && ! current_user_can( 'administrator' ) ) {
					$caps[] = 'do_not_allow';
				}

				// Shop managers can only edit customer info.
				if ( current_user_can( 'shop_manager' ) ) {
					$userdata = get_userdata( $args[0] );
					$shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
					if ( property_exists( $userdata, 'roles' ) && ! empty( $userdata->roles ) && ! array_intersect( $userdata->roles, $shop_manager_editable_roles ) ) {
						$caps[] = 'do_not_allow';
					}
				}
			}
			break;
	}
	return $caps;
}

Workaround – remove/comment part with condition for ‘shop_manager’ or use ‘woocommerce_shop_manager_editable_roles’ custom filter to not restrict editable roles for superadmin.