Automattic\WooCommerce\Internal\PushNotifications\Services
NotificationPreferencesService::sanitize
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
Usage
// private - for code of main (parent) class only $result = $this->sanitize( $preferences ): array;
- $preferences(array) (required)
- Arbitrary preferences map.
NotificationPreferencesService::sanitize() 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;
}