Automattic\WooCommerce\Internal\PushNotifications\Services

NotificationPreferencesService::sanitizeprivateWC 1.0

Drop unknown top-level keys and unknown sub-fields per key, coercing known sub-fields to their expected types.

Method of the class: NotificationPreferencesService{}

No Hooks.

Returns

Array. array<string, mixed>> Sanitized preferences.

Usage

// private - for code of main (parent) class only
$result = $this->sanitize( $preferences ): array;
$preferences(array) (required)
Arbitrary preferences map.

NotificationPreferencesService::sanitize() code WC 10.9.1

private function sanitize( array $preferences ): array {
	$allowed   = $this->get_defaults();
	$sanitized = array();

	foreach ( $allowed as $key => $default_shape ) {
		$value             = $preferences[ $key ] ?? array();
		$value             = is_array( $value ) ? $value : array();
		$sanitized[ $key ] = $this->sanitize_value( $key, $value, $default_shape );
	}

	return $sanitized;
}