Yoast\WP\SEO\AI\Consent\User_Interface

Consent_Route::consentpublicYoast 1.0

Runs the callback to store the consent given by the user to use AI-based services.

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

Хуков нет.

Возвращает

WP_REST_Response. The response of the callback action.

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

$Consent_Route = new Consent_Route();
$Consent_Route->consent( $request ): WP_REST_Response;
$request(WP_REST_Request) (обязательный)
The request object.

Код Consent_Route::consent() Yoast 28.3

public function consent( WP_REST_Request $request ): WP_REST_Response {
	$user_id = \get_current_user_id();
	$consent = (bool) $request->get_param( 'consent' );

	try {
		if ( $consent ) {
			// Store the consent at user level.
			$this->consent_handler->grant_consent( $user_id );
		}
		else {
			// Revoke the consent locally and remotely (this also invalidates the JWT tokens).
			$this->consent_handler->revoke_consent( $user_id );
		}
	} catch ( Remote_Request_Exception | RuntimeException $e ) {
		$status_code = ( $e instanceof Remote_Request_Exception ) ? $e->getCode() : 500;
		$this->logger->error( $e->getMessage(), [ 'exception' => $e ] );
		return new WP_REST_Response( ( $consent ) ? 'Failed to give consent.' : 'Failed to revoke consent.', $status_code );
	}

	return new WP_REST_Response( ( $consent ) ? 'Consent successfully given.' : 'Consent successfully revoked.' );
}