Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Pieces

Edd_Schema_Piece_Repository::collectpublicYoast 1.0

Collects download schema pieces for EDD downloads.

Triggers EDD's schema generation. Returns the captured Product entity.

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

Хуков нет.

Возвращает

Массив<Массив<Строку,Строку|int|true|false|Массив>>. Product schema pieces (empty array if unavailable).

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

$Edd_Schema_Piece_Repository = new Edd_Schema_Piece_Repository();
$Edd_Schema_Piece_Repository->collect( $post_id ): array;
$post_id(int) (обязательный)
Download post ID.

Код Edd_Schema_Piece_Repository::collect() Yoast 28.3

public function collect( int $post_id ): array {
	if ( ! $this->edd_conditional->is_met() ) {
		return [];
	}

	try {
		$structured_data = new Structured_Data();
		$structured_data->generate_download_data( $post_id );
		$schema_output = $structured_data->get_data();

		if ( ! \is_array( $schema_output ) || empty( $schema_output ) ) {
			return [];
		}

		// Ensure each piece has an @id.
		foreach ( $schema_output as $key => $piece ) {
			if ( ! isset( $piece['@id'] ) ) {
				$schema_output[ $key ]['@id'] = $this->meta->for_post( $post_id )->canonical . '#/schema/edd-product/' . $post_id;
			}
		}

		return $schema_output;
	} catch ( Exception $e ) {
		return [];
	}
}