Automattic\WooCommerce\Admin\API
MobileAppQRLogin::sanitize_device_payload
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
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() 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;
}