Yoast\WP\SEO\AI\Content_Planner\Application
Content_Suggestion_Command_Handler::handle
Handles the content suggestion command by collecting recent content and requesting suggestions from the AI API.
Метод класса: Content_Suggestion_Command_Handler{}
Хуков нет.
Возвращает
Content_Suggestion_Response. The response containing suggestions and recent content.
Использование
$Content_Suggestion_Command_Handler = new Content_Suggestion_Command_Handler(); $Content_Suggestion_Command_Handler->handle( $command ): Content_Suggestion_Response;
- $command(Content_Suggestion_Command) (обязательный)
- The content suggestion command.
Код Content_Suggestion_Command_Handler::handle() Content Suggestion Command Handler::handle Yoast 28.9
public function handle( Content_Suggestion_Command $command ): Content_Suggestion_Response {
$recent_content = $this->recent_content_collector->collect( $command->get_post_type() );
$about_page = $this->recent_content_collector->collect_about_page( $command->get_post_type() );
$content = [
'posts' => $recent_content->to_array(),
];
if ( $about_page ) {
$content['about_page'] = $about_page;
}
$parameters = new Content_Suggestion_Parameters(
$command->get_user(),
$command->get_language(),
$content,
$command->get_editor(),
);
try {
$sender = $this->ai_request_sender_factory->create( $command->get_user() );
$response = $sender->get_content_suggestions( $parameters );
} catch ( Insufficient_Scope_Exception $exception ) {
throw $exception;
} catch ( Forbidden_Exception $exception ) {
$this->consent_handler->revoke_consent( $command->get_user()->ID );
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- false positive.
throw new Forbidden_Exception( 'CONSENT_REVOKED', $exception->getCode() );
}
return $this->build_response( $response, $recent_content );
}