Automattic\WooCommerce\Admin\API

MobileAppQRLogin::sanitize_device_payloadprivateWC 1.0

Whitelist + sanitize the device payload sent by the mobile app.

Returns an array of strings keyed by the whitelisted keys defined in DEVICE_PAYLOAD_KEYS. Anything outside that whitelist is dropped. Each value is run through sanitize_text_field() capped at DEVICE_FIELD_MAX_LENGTH characters. The function is total — pass null or anything non-array and you get back array().

Method of the class: MobileAppQRLogin{}

No Hooks.

Returns

Array. string>

Usage

// private - for code of main (parent) class only
$result = $this->sanitize_device_payload( $device );
$device(mixed) (required)
Raw payload from the request.

MobileAppQRLogin::sanitize_device_payload() code WC 11.0.1

private function sanitize_device_payload( $device ) {
	if ( ! is_array( $device ) ) {
		return array();
	}

	$sanitized = array();
	foreach ( self::DEVICE_PAYLOAD_KEYS as $key ) {
		if ( ! isset( $device[ $key ] ) || ! is_scalar( $device[ $key ] ) ) {
			continue;
		}
		$value = sanitize_text_field( (string) $device[ $key ] );
		if ( '' === $value ) {
			continue;
		}
		if ( strlen( $value ) > self::DEVICE_FIELD_MAX_LENGTH ) {
			$value = substr( $value, 0, self::DEVICE_FIELD_MAX_LENGTH );
		}
		$sanitized[ $key ] = $value;
	}

	return $sanitized;
}