Automattic\WooCommerce\Internal\PushNotifications\DataStores

PushTokensDataStore::updatepublicWC 10.5.0

Updates a post representing the push token.

Метод класса: PushTokensDataStore{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$PushTokensDataStore = new PushTokensDataStore();
$PushTokensDataStore->update( $push_token ): void;
$push_token(PushToken) (обязательный)
An instance of PushToken.

Список изменений

С версии 10.5.0 Введена.

Код PushTokensDataStore::update() WC 10.5.2

public function update( PushToken &$push_token ): void {
	if ( ! $push_token->can_be_updated() ) {
		throw new InvalidArgumentException(
			'Can\'t update push token because the push token data provided is invalid.'
		);
	}

	$post = get_post( $push_token->get_id() );

	if ( ! $post || PushToken::POST_TYPE !== $post->post_type ) {
		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
		throw new PushTokenNotFoundException( 'Push token could not be found.' );
	}

	$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:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
		throw new Exception( $result->get_error_message() );
	}

	if ( null === $push_token->get_device_uuid() ) {
		delete_post_meta( (int) $push_token->get_id(), 'device_uuid' );
	}
}