Yoast\WP\SEO\AI\Content_Planner\Application
Content_Outline_Command_Handler::handle
Handles the content outline command by collecting recent content and requesting an outline from the AI API.
Метод класса: Content_Outline_Command_Handler{}
Хуков нет.
Возвращает
Section_List. A list of outline sections.
Использование
$Content_Outline_Command_Handler = new Content_Outline_Command_Handler(); $Content_Outline_Command_Handler->handle( $command ): Section_List;
- $command(Content_Outline_Command) (обязательный)
- The content outline command.
Код Content_Outline_Command_Handler::handle() Content Outline Command Handler::handle Yoast 28.3
public function handle( Content_Outline_Command $command ): Section_List {
$recent_content = $command->get_recent_content();
$about_page = $this->recent_content_collector->collect_about_page( $command->get_post_type() );
$existing_posts = \array_map(
static function ( $post ) {
return [
'title' => $post['title'],
'description' => $post['description'],
];
},
$recent_content,
);
$content = [
'new_post_metadata' => [
'title' => $command->get_title(),
'intent' => $command->get_intent(),
'explanation' => $command->get_explanation(),
'keyphrase' => $command->get_keyphrase(),
'meta_description' => $command->get_meta_description(),
'category' => $command->get_category()->to_array(),
],
'existing_posts' => $existing_posts,
];
if ( $about_page ) {
$content['about_page'] = $about_page;
}
$parameters = new Content_Outline_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_outline_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
throw new Forbidden_Exception( 'CONSENT_REVOKED', $exception->getCode() );
}
return $this->build_outline( $response );
}