Yoast\WP\SEO\Bulk_Editor\Infrastructure\Posts

Indexable_Posts_Collector::build_needs_improvement │ private │ Yoast 1.0

Builds the per-field needs-improvement verdict for a post, keyed by field param.

A field needs improvement when its value is empty, or when its score falls in the bad/ok range. All four display values are passed in already-resolved so that a post whose stored value is empty but whose post type has a configured default template is not incorrectly flagged.

Метод класса: Indexable_Posts_Collector{}

Хуков нет.

Возвращает

array<string, bool>. Whether each field needs improvement, keyed by field param.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->build_needs_improvement( $indexable, $scores_enabled, $resolved_values ): array;
$indexable(Indexable) (обязательный)
The indexable.
$scores_enabled(true|false) (обязательный)
Whether the per-field scores may back the verdict.
$resolved_values(array<string, string>) (обязательный)
The resolved display values, keyed by field param.

Код Indexable_Posts_Collector::build_needs_improvement() Yoast 28.9

private function build_needs_improvement( Indexable $indexable, bool $scores_enabled, array $resolved_values ): array {
	$needs_improvement = [];
	foreach ( self::FIELD_COLUMNS as $field => $column ) {
		$value    = $resolved_values[ $field ];
		$is_empty = ( $value === '' );

		$is_bad_score = false;
		if ( $scores_enabled && isset( self::FIELD_SCORE_COLUMNS[ $field ] ) ) {
			$score        = (int) $indexable->{self::FIELD_SCORE_COLUMNS[ $field ]};
			$is_bad_score = ( $score >= self::NEEDS_IMPROVEMENT_MIN_SCORE && $score <= self::NEEDS_IMPROVEMENT_MAX_SCORE );
		}

		$needs_improvement[ $field ] = ( $is_empty || $is_bad_score );
	}

	return $needs_improvement;
}