Carbon_Fields\Container\User_Meta_Container::is_valid_save_conditions PHP Method

is_valid_save_conditions() public method

Perform checks whether the current save() request is valid
public is_valid_save_conditions ( integer $user_id ) : boolean
$user_id integer ID of the user against which save() is ran
return boolean
    public function is_valid_save_conditions($user_id)
    {
        $valid = true;
        $user = get_userdata($user_id);
        if (empty($user->roles)) {
            return;
        }
        // Check user role
        if (!empty($this->settings['show_on']['role'])) {
            $allowed_roles = (array) $this->settings['show_on']['role'];
            // array_shift removed the returned role from the $user_profile->roles
            // $roles_to_shift prevents changing of the $user_profile->roles variable
            $roles_to_shift = $user->roles;
            $profile_role = array_shift($roles_to_shift);
            if (!in_array($profile_role, $allowed_roles)) {
                $valid = false;
            }
        }
        return $valid;
    }