Yoast\WP\SEO\AI\Content_Planner\Application
Content_Suggestion_Command_Handler::build_suggestions_array
Builds a list of content suggestions from the API response.
Метод класса: Content_Suggestion_Command_Handler{}
Хуков нет.
Возвращает
Content_Suggestion_List. The list of content suggestions.
Использование
$Content_Suggestion_Command_Handler = new Content_Suggestion_Command_Handler(); $Content_Suggestion_Command_Handler->build_suggestions_array( $response ): Content_Suggestion_List;
- $response(Response) (обязательный)
- The API response.
Код Content_Suggestion_Command_Handler::build_suggestions_array() Content Suggestion Command Handler::build suggestions array Yoast 27.7
public function build_suggestions_array( Response $response ): Content_Suggestion_List {
$content_suggestion_list = new Content_Suggestion_List();
$json = \json_decode( $response->get_body() );
if ( $json === null || ! isset( $json->choices ) ) {
return $content_suggestion_list;
}
foreach ( $json->choices as $suggestion ) {
$category = $this->category_repository->find_by_name( $suggestion->category->name );
$content_suggestion_list->add(
new Content_Suggestion(
$suggestion->title,
$suggestion->intent,
$suggestion->explanation,
$suggestion->keyphrase,
$suggestion->meta_description,
$category,
),
);
}
return $content_suggestion_list;
}