Yoast\WP\SEO\AI_Consent\Application
Consent_Handler::grant_consent
Устарела с версии 28.4. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.
Records the user's consent on the Yoast AI service and, on success, in the local user meta.
Transactional: any HTTP-layer exception is propagated and the local meta is left untouched, so the local and server state stay in sync.
Метод класса: Consent_Handler{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
$Consent_Handler = new Consent_Handler(); $Consent_Handler->grant_consent( $user_id );
- $user_id(int) (обязательный)
- The user ID.
Список изменений
| Устарела с | 28.4 |
Код Consent_Handler::grant_consent() Consent Handler::grant consent Yoast 28.9
public function grant_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" );
}
$jwt = $this->token_manager->get_or_request_access_token( $user );
$body = [
'user_id' => (string) $user_id,
];
$this->request_handler->handle(
new Request( '/user/consent', $body, [ 'Authorization' => "Bearer $jwt" ], Request::METHOD_POST ),
);
$this->user_helper->update_meta( $user_id, '_yoast_wpseo_ai_consent', true );
}