Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\SEO_Score_Results
SEO_Score_Results_Collector::get_score_results
Retrieves the SEO score results for a content type.
Метод класса: SEO_Score_Results_Collector{}
Хуков нет.
Возвращает
Массив<Строку,. object|bool|float> The SEO score results for a content type.
Использование
$SEO_Score_Results_Collector = new SEO_Score_Results_Collector(); $SEO_Score_Results_Collector->get_score_results( $seo_score_groups, $content_type, ?int $term_id, ?bool $is_troubleshooting ): array;
- $seo_score_groups(SEO_Score_Groups_Interface[]) (обязательный)
- All SEO score groups.
- $content_type(Content_Type) (обязательный)
- The content type.
- ?int $term_id(обязательный)
- .
- ?bool $is_troubleshooting(обязательный)
- .
Код SEO_Score_Results_Collector::get_score_results() SEO Score Results Collector::get score results Yoast 27.3
public function get_score_results( array $seo_score_groups, Content_Type $content_type, ?int $term_id, ?bool $is_troubleshooting ): array {
global $wpdb;
$results = [];
$content_type_name = $content_type->get_name();
$select = $this->build_select( $seo_score_groups, $is_troubleshooting );
$replacements = \array_merge(
\array_values( $select['replacements'] ),
[
Model::get_table_name( 'Indexable' ),
$content_type_name,
],
);
if ( $term_id === null ) {
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- $replacements is an array with the correct replacements.
//phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $select['fields'] is an array of simple strings with placeholders.
$query = $wpdb->prepare(
"
SELECT {$select['fields']}
FROM %i AS I
WHERE ( I.post_status = 'publish' OR I.post_status IS NULL )
AND I.object_type = 'post'
AND I.object_sub_type = %s
AND ( I.is_robots_noindex IS NULL OR I.is_robots_noindex <> 1 )",
$replacements,
);
//phpcs:enable
}
else {
$replacements[] = $wpdb->term_relationships;
$replacements[] = $term_id;
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- $replacements is an array with the correct replacements.
//phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $select['fields'] is an array of simple strings with placeholders.
$query = $wpdb->prepare(
"
SELECT {$select['fields']}
FROM %i AS I
WHERE ( I.post_status = 'publish' OR I.post_status IS NULL )
AND I.object_type IN ('post')
AND I.object_sub_type = %s
AND ( I.is_robots_noindex IS NULL OR I.is_robots_noindex <> 1 )
AND I.object_id IN (
SELECT object_id
FROM %i
WHERE term_taxonomy_id = %d
)",
$replacements,
);
//phpcs:enable
}
$start_time = \microtime( true );
//phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- $query is prepared above.
//phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
//phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
$current_scores = $wpdb->get_row( $query );
//phpcs:enable
if ( $current_scores === null ) {
throw new Score_Results_Not_Found_Exception();
}
$end_time = \microtime( true );
$results['scores'] = $current_scores;
$results['query_time'] = ( $end_time - $start_time );
return $results;
}