Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\Readability_Score_Results
Readability_Score_Results_Collector::get_score_results()
Retrieves readability score results for a content type.
Метод класса: Readability_Score_Results_Collector{}
Хуков нет.
Возвращает
Массив<Строку,
. object|bool|float> The readability score results for a content type.
Использование
$Readability_Score_Results_Collector = new Readability_Score_Results_Collector(); $Readability_Score_Results_Collector->get_score_results( $readability_score_groups, $content_type, ?int $term_id, ?bool $is_troubleshooting );
- $readability_score_groups(Readability_Score_Groups_Interface[]) (обязательный)
- All readability score groups.
- $content_type(Content_Type) (обязательный)
- The content type.
- ?int $term_id (обязательный)
- -
- ?bool $is_troubleshooting (обязательный)
- -
Код Readability_Score_Results_Collector::get_score_results() Readability Score Results Collector::get score results Yoast 24.4
public function get_score_results( array $readability_score_groups, Content_Type $content_type, ?int $term_id, ?bool $is_troubleshooting ) { global $wpdb; $results = []; $content_type_name = $content_type->get_name(); $select = $this->build_select( $readability_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", $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 = 'post' AND I.object_sub_type = %s 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; }