Automattic\WooCommerce\Internal\PushNotifications\DataStores
PushTokensDataStore::update
Updates a post representing the push token.
Method of the class: PushTokensDataStore{}
No Hooks.
Returns
true|false. True on success.
Usage
$PushTokensDataStore = new PushTokensDataStore(); $PushTokensDataStore->update( $push_token ): bool;
- $push_token(PushToken) (required)
- The push token to update.
Changelog
| Since 10.5.0 | Introduced. |
PushTokensDataStore::update() PushTokensDataStore::update code WC 10.8.1
public function update( PushToken $push_token ): bool {
if ( ! $push_token->can_be_updated() ) {
throw new PushTokenInvalidDataException(
'Can\'t update push token because the push token data provided is invalid.'
);
}
$result = wp_update_post(
array(
'ID' => (int) $push_token->get_id(),
'post_author' => (int) $push_token->get_user_id(),
'post_type' => PushToken::POST_TYPE,
'post_status' => 'private',
'meta_input' => $this->build_meta_array_from_token( $push_token ),
),
true
);
if ( is_wp_error( $result ) ) {
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new WC_Data_Exception(
(string) $result->get_error_code(),
$result->get_error_message(),
WP_Http::INTERNAL_SERVER_ERROR
);
// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
if ( null === $push_token->get_device_uuid() ) {
delete_post_meta( (int) $push_token->get_id(), 'device_uuid' );
}
return true;
}