Yoast\WP\SEO\Actions\Wincher
Wincher_Keyphrases_Action::get_tracked_keyphrases
Gets the keyphrase data for the passed keyphrases. Retrieves all available data if no keyphrases are provided.
Метод класса: Wincher_Keyphrases_Action{}
Хуков нет.
Возвращает
Объект. The keyphrase chart data.
Использование
$Wincher_Keyphrases_Action = new Wincher_Keyphrases_Action(); $Wincher_Keyphrases_Action->get_tracked_keyphrases( $used_keyphrases, $permalink, $start_at );
- $used_keyphrases(массив|null)
- The currently used keyphrases. Optional.
По умолчанию:null - $permalink(строка|null)
- The current permalink. Optional.
По умолчанию:null - $start_at(строка|null)
- The position start date. Optional.
По умолчанию:null
Код Wincher_Keyphrases_Action::get_tracked_keyphrases() Wincher Keyphrases Action::get tracked keyphrases Yoast 28.2
public function get_tracked_keyphrases( $used_keyphrases = null, $permalink = null, $start_at = null ) {
try {
$used_keyphrases ??= $this->collect_all_keyphrases();
// If we still have no keyphrases the API will return an error, so
// don't even bother sending a request.
if ( empty( $used_keyphrases ) ) {
return $this->to_result_object(
[
'data' => [],
'status' => 200,
],
);
}
$endpoint = \sprintf(
self::KEYPHRASES_URL,
$this->options_helper->get( 'wincher_website_id' ),
);
$results = $this->client->post(
$endpoint,
WPSEO_Utils::format_json_encode(
[
'keywords' => $used_keyphrases,
'url' => $permalink,
'start_at' => $start_at,
],
),
[
'timeout' => 60,
],
);
if ( ! \array_key_exists( 'data', $results ) ) {
return $this->to_result_object( $results );
}
$results['data'] = $this->filter_results_by_used_keyphrases( $results['data'], $used_keyphrases );
// Extract the positional data and assign it to the keyphrase.
$results['data'] = \array_combine(
\array_column( $results['data'], 'keyword' ),
\array_values( $results['data'] ),
);
return $this->to_result_object( $results );
} catch ( Exception $e ) {
return (object) [
'error' => $e->getMessage(),
'status' => $e->getCode(),
];
}
}