Yoast\WP\SEO\Generators\Schema\Third_Party
Events_Calendar_Schema::transform_tribe_schema() private Yoast 1.0
Transform the tribe schema markup and adapt it to the Yoast SEO standard.
{} Это метод класса: Events_Calendar_Schema{}
Хуков нет.
Возвращает
Массив. The transformed event data.
Использование
// private - только в коде основоного (родительского) класса $result = $this->transform_tribe_schema( $data );
- $data(массив)
- The data retrieved from the TEC plugin.
По умолчанию: []
Код Events_Calendar_Schema::transform_tribe_schema() Events Calendar Schema::transform tribe schema Yoast 15.6.2
private function transform_tribe_schema( array $data = [] ) {
$new_data = [];
foreach ( $data as $post_id => $d ) {
$permalink = \get_permalink( $post_id );
// EVENT.
// Generate an @id for the event.
$d->{'@id'} = $permalink . '#' . \strtolower( \esc_attr( $d->{'@type'} ) );
// Transform the post_thumbnail from the url to the @id of #primaryimage.
if ( \has_post_thumbnail( $post_id ) ) {
if ( \is_singular( 'tribe_events' ) ) {
// On a single view we can assume that Yoast SEO already printed the
// image schema for the post thumbnail.
$d->image = (object) [
'@id' => $permalink . '#primaryimage',
];
}
else {
$image_id = \get_post_thumbnail_id( $post_id );
$schema_id = $permalink . '#primaryimage';
$d->image = $this->helpers->schema->image->generate_from_attachment_id( $schema_id, $image_id );
}
}
if ( isset( $d->description ) && ! empty( $d->description ) ) {
// By the time the description arrives in this plugin it is heavily
// escaped. That's why we basically pull new text from the database.
$d->description = \get_the_excerpt( $post_id );
}
// ORGANIZER.
if ( \tribe_has_organizer( $post_id ) ) {
if ( ! $d->organizer ) {
$d->organizer = new stdClass();
}
$organizer_id = \tribe_get_organizer_id( $post_id );
$d->organizer->description = \get_the_excerpt( $organizer_id );
// Fix empty organizer/url and wrong organizer/sameAs.
if ( isset( $d->organizer->sameAs ) && $d->organizer->url === false ) {
$d->organizer->url = $d->organizer->sameAs;
}
unset( $d->organizer->sameAs );
}
// VENUE / LOCATION.
if ( \tribe_has_venue( $post_id ) ) {
if ( ! $d->location ) {
$d->location = new stdClass();
}
$venue_id = \tribe_get_venue_id( $post_id );
$d->location->description = \get_the_excerpt( $venue_id );
}
/*
* PERFORMER
* Unset the performer, as it is currently unused.
* @see: https://github.com/moderntribe/the-events-calendar/blob/5e737eb820c59bb9639d9ee9f4b88931a51c8554/src/Tribe/JSON_LD/Event.php#L151
*/
unset( $d->performer );
// OFFERS.
if ( isset( $d->offers ) && \is_array( $d->offers ) ) {
foreach ( $d->offers as $key => $offer ) {
unset( $d->offers[ $key ]->category );
}
}
$new_data[ $post_id ] = $d;
}
return $new_data;
}