Yoast\WP\SEO\AI_Consent\Application

Consent_Handler::revoke_consent │ public │ Yoast 1.0

Устарела с версии 28.4. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.

Revokes the user's consent, both locally (user meta) and remotely (Yoast AI service).

Security-first: the local meta is always cleared before the remote call, so consent is revoked locally even if the remote DELETE /user/consent fails. Any locally stored JWTs are then invalidated regardless of the remote outcome — credentials must not outlive consent. The invalidation runs after the DELETE on purpose: authenticating the DELETE may mint a fresh JWT, and invalidating afterwards catches that token too. Any HTTP-layer exception is propagated and its management is deferred to the caller.

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

Хуков нет.

Возвращает

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

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

$Consent_Handler = new Consent_Handler();
$Consent_Handler->revoke_consent( $user_id );
$user_id(int) (обязательный)
The user ID.

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

Устарела с 28.4

Код Consent_Handler::revoke_consent() Yoast 28.9

public function revoke_consent( int $user_id ) {
	\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );
	$user = \get_user_by( 'id', $user_id );
	if ( ! $user instanceof WP_User ) {
		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- false positive.
		throw new RuntimeException( "User not found: $user_id" );
	}
	// Local consent is always revoked regardless of remote failures.
	$this->user_helper->delete_meta( $user_id, '_yoast_wpseo_ai_consent' );

	try {
		$jwt = $this->token_manager->get_or_request_access_token( $user );

		$this->request_handler->handle(
			new Request( '/user/consent', [], [ 'Authorization' => "Bearer $jwt" ], Request::METHOD_DELETE ),
		);
	} finally {
		// Invalidate the JWTs — including ones minted to authenticate the DELETE above — so
		// credentials never outlive consent.
		if ( $this->token_manager->has_local_tokens( $user_id ) ) {
			$this->token_manager->token_invalidate( $user_id );
		}
	}
}