Automattic\WooCommerce\Internal\PushNotifications\Entities
PushToken::set_metadata
Validates and sets the metadata.
Method of the class: PushToken{}
No Hooks.
Returns
null. Nothing (null).
Usage
$PushToken = new PushToken(); $PushToken->set_metadata( $metadata ): void;
- $metadata(array) (required)
- An array of metadata for the token, e.g. the app version, device OS etc.
Changelog
| Since 10.6.0 | Introduced. |
PushToken::set_metadata() PushToken::set metadata code WC 10.8.1
public function set_metadata( array $metadata ): void {
$result = PushTokenValidator::validate( compact( 'metadata' ), array( 'metadata' ) );
if ( is_wp_error( $result ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new PushTokenInvalidDataException( $result->get_error_message() );
}
if ( ! empty( $metadata ) ) {
$keys = array_map( 'sanitize_key', array_keys( $metadata ) );
$values = array_map( 'sanitize_text_field', array_values( $metadata ) );
/**
* Typehint for PHPStan, as it can't infer the $keys and $values are
* the same length therefore array_combine won't return false.
*
* @var array<string, string> $metadata
*/
$metadata = array_combine( $keys, $values );
}
$this->metadata = $metadata;
}