wc_modify_editable_roles()WC 1.0

Modify the list of editable roles to prevent non-admin adding admin users.

Hooks from the function

Return

Array.

Usage

wc_modify_editable_roles( $roles );
$roles(array) (required)
Roles.

wc_modify_editable_roles() code WC 9.4.2

function wc_modify_editable_roles( $roles ) {
	if ( is_multisite() && is_super_admin() ) {
		return $roles;
	}
	if ( ! wc_current_user_has_role( 'administrator' ) ) {
		unset( $roles['administrator'] );

		if ( wc_current_user_has_role( 'shop_manager' ) ) {
			$shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
			return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );
		}
	}

	return $roles;
}