Yoast\WP\SEO\Schema_Aggregator\Application\Enhancement

Article_Schema_Enhancer::enhance_schema_pieceprotectedYoast 1.0

Enhance a single schema piece

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

Хуков нет.

Возвращает

Массив<Строку>. The enhanced schema data.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->enhance_schema_piece( $schema_data, $indexable ): array;
$schema_data(array) (обязательный)
The schema data to enhance.
$indexable(Indexable) (обязательный)
The indexable object that is the source of the schema piece.

Код Article_Schema_Enhancer::enhance_schema_piece() Yoast 27.7

protected function enhance_schema_piece( array $schema_data, Indexable $indexable ): array {
	try {
		$has_excerpt = false;

		if ( $this->config->is_enhancement_enabled( 'use_excerpt' ) ) {
			$excerpt     = $this->get_excerpt( $indexable->object_id );
			$has_excerpt = ! empty( $excerpt );

			if ( $has_excerpt && ! isset( $schema_data['description'] ) ) {
				$schema_data['description'] = $excerpt;
			}
		}

		if ( $this->config->is_enhancement_enabled( 'article_body' ) && ! isset( $schema_data['articleBody'] ) ) {
			if ( $this->config->should_include_article_body( $has_excerpt ) ) {
				$article_body = $this->get_article_body( $indexable->object_id );
				if ( ! empty( $article_body ) ) {
					$schema_data['articleBody'] = $article_body;
				}
			}
		}

		if ( $this->config->is_enhancement_enabled( 'keywords' ) ) {
			$keywords = $this->get_article_keywords( $indexable->object_id );
			if ( ! empty( $keywords ) ) {
				$existing                = (array) ( $schema_data['keywords'] ?? [] );
				$schema_data['keywords'] = \implode( ', ', \array_unique( \array_merge( $existing, $keywords ) ) );
			}
		}

		return $schema_data;
	} catch ( Exception $e ) {
		return $schema_data;
	}
}