Yoast\WP\SEO\AI\Consent\Application

Consent_Handler::revoke_consentpublicYoast 1.0

Revokes the user's consent on the Yoast AI service and clears the local user meta.

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 legacy JWTs are then invalidated regardless of the remote outcome — credentials must not outlive consent. The invalidation runs after the DELETE on purpose: the legacy Token path may mint a fresh JWT to authenticate the DELETE, and invalidating afterwards catches that token too. Any HTTP-layer exception is propagated and its management is deferred to the caller.

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

Хуков нет.

Возвращает

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

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

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

Код Consent_Handler::revoke_consent() Yoast 28.3

public function revoke_consent( int $user_id ) {
	$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 {
		$this->ai_request_sender_factory->create( $user )->revoke_consent( $user );
	} finally {
		// Invalidate the legacy JWTs — including ones minted to authenticate the DELETE above —
		// so credentials never outlive consent. Skipped when no local JWTs exist (the OAuth path
		// without a leftover pre-OAuth grant).
		if ( $this->token_manager->has_local_tokens( $user_id ) ) {
			$this->token_manager->token_invalidate( $user_id );
		}
	}
}