Yoast\WP\SEO\Bulk_Editor\Infrastructure\Posts
Indexable_Posts_Collector::apply_needs_improvement
Adds the "needs improvement" clause to the query.
A field needs improvement when its indexable column is NULL or an empty string, or — for fields with a persisted per-field score and while scoring is enabled — when that score falls in the bad/ok range. The empty-value check is skipped for fields whose post type has a configured fallback template, since template-defaulted posts are not genuinely empty. The selected fields are OR-ed inside a single group so they broaden the result without interfering with the other filters, and unknown field keys are ignored.
Метод класса: Indexable_Posts_Collector{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->apply_needs_improvement( $builder, $fields, $scores_enabled, $post_type ): void;
- $builder(ORM) (обязательный)
- The query to add the clause to.
- $fields(array
) (обязательный) - The fields that need improvement.
- $scores_enabled(true|false) (обязательный)
- Whether the per-field scores may back the filter.
- $post_type(строка) (обязательный)
- The post type slug.
Код Indexable_Posts_Collector::apply_needs_improvement() Indexable Posts Collector::apply needs improvement Yoast 28.7
private function apply_needs_improvement( ORM $builder, array $fields, bool $scores_enabled, string $post_type ): void {
$has_fallback = [
'seo_title' => $this->default_template_resolver->resolve_seo_title( 0, $post_type, '' ) !== '',
'meta_description' => $this->default_template_resolver->resolve_meta_description( 0, $post_type, '' ) !== '',
'social_title' => $this->default_template_resolver->resolve_social_title( 0, $post_type, '' ) !== '',
'social_description' => $this->default_template_resolver->resolve_social_description( 0, $post_type, '' ) !== '',
];
$clauses = [];
$values = [];
foreach ( $fields as $field ) {
if ( ! isset( self::FIELD_COLUMNS[ $field ] ) ) {
continue;
}
$column = self::FIELD_COLUMNS[ $field ];
$field_clauses = [];
if ( ! ( $has_fallback[ $field ] ?? false ) ) {
$field_clauses[] = $column . ' IS NULL OR ' . $column . ' = %s';
$values[] = '';
}
if ( $scores_enabled && isset( self::FIELD_SCORE_COLUMNS[ $field ] ) ) {
$field_clauses[] = self::FIELD_SCORE_COLUMNS[ $field ] . ' BETWEEN %d AND %d';
$values[] = self::NEEDS_IMPROVEMENT_MIN_SCORE;
$values[] = self::NEEDS_IMPROVEMENT_MAX_SCORE;
}
// Always add a clause per field — use a false condition when no real predicate applies so the
// field still participates in the outer OR group without incorrectly matching every row.
$clauses[] = '( ' . ( ( $field_clauses !== [] ) ? \implode( ' OR ', $field_clauses ) : '1 = 0' ) . ' )';
}
if ( $clauses === [] ) {
return;
}
// The column names come from the internal maps, never from input; only the empty string and score bounds are bound.
$builder->where_raw(
'( ' . \implode( ' OR ', $clauses ) . ' )',
$values,
);
}