Skip to content

Commit

Permalink
Add compatibility for Yoast 14.0 (#26)
Browse files Browse the repository at this point in the history
* Revert "Revert "Add compatibility for Yoast 14.0""

This reverts commit 20f6cee.

* Update readme.txt

* Catch some more errors
  • Loading branch information
Luehrsen authored Jun 22, 2020
1 parent d4176de commit bcfa9d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
42 changes: 22 additions & 20 deletions build/inc/Yoast_Event_Schema/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,29 @@

namespace wpmyte\Yoast_Event_Schema;
use wpmyte\Component_Interface;
use WPSEO_Graph_Piece;
use WPSEO_Schema_Context;
use WPSEO_Schema_Image;
use WPSEO_Schema_IDs;
use \Yoast\WP\SEO\Generators\Schema\Abstract_Schema_Piece;
use \Yoast\WP\SEO\Config\Schema_IDs;
use Tribe__Events__JSON_LD__Event;
use Tribe__Events__Template__Month;
use function load_plugin_textdomain;

/**
* A class to handle textdomains and other Yoast Event Schema related logic..
*/
class Component implements Component_Interface, WPSEO_Graph_Piece {
class Component extends Abstract_Schema_Piece implements Component_Interface {
/**
* A value object with context variables.
* The meta tags context.
*
* @var WPSEO_Schema_Context
* @var Meta_Tags_Context
*/
private $context;
public $context;

/**
* Schema_Event constructor.
* The helpers surface
*
* @param WPSEO_Schema_Context $context Value object with context variables.
* @var Helpers_Surface
*/
public function __construct( WPSEO_Schema_Context $context ) {
$this->context = $context;
}
public $helpers;

/**
* Gets the unique identifier for the plugin component.
Expand Down Expand Up @@ -105,7 +101,7 @@ public function generate() {
// If the resulting array only has one entry, print it directly.
if ( count( $data ) === 1 ) {
$data = $data[0];
$data['mainEntityOfPage'] = [ '@id' => $this->context->canonical . WPSEO_Schema_IDs::WEBPAGE_HASH ];
$data['mainEntityOfPage'] = [ '@id' => $this->context->canonical . Schema_IDs::WEBPAGE_HASH ];
} elseif ( count( $data ) === 0 ) {
$data = false;
}
Expand Down Expand Up @@ -175,10 +171,9 @@ private function transform_tribe_schema( array $data = [] ) {
'@id' => get_permalink( $post_id ) . '#primaryimage',
];
} else {
$image_id = get_post_thumbnail_id( $post_id );
$schema_id = get_permalink( $post_id ) . '#primaryimage';
$schema_image = new WPSEO_Schema_Image( $schema_id );
$d->image = $schema_image->generate_from_attachment_id( $image_id );
$image_id = get_post_thumbnail_id( $post_id );
$schema_id = get_permalink( $post_id ) . '#primaryimage';
$d->image = $this->helpers->schema->image->generate_from_attachment_id( $schema_id, $image_id );
}
}

Expand All @@ -192,11 +187,15 @@ private function transform_tribe_schema( array $data = [] ) {
* 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 ( $d->organizer->url === false ) {
if ( isset( $d->organizer->sameAs ) && $d->organizer->url === false ) {
$d->organizer->url = $d->organizer->sameAs;
}
unset( $d->organizer->sameAs );
Expand All @@ -206,6 +205,10 @@ private function transform_tribe_schema( array $data = [] ) {
* 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 );
}
Expand All @@ -214,7 +217,6 @@ private function transform_tribe_schema( array $data = [] ) {
* 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 );

Expand Down
3 changes: 3 additions & 0 deletions build/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ If you are using both The Events Calender and Yoast SEO on your WordPress, using

A more detailed changelog can be [found on GitHub](https://github.com/luehrsenheinrich/yoast-schema-tribe-events/releases).

= 1.2.0 =
* Updated the Yoast SEO Schema syntax to match Version 14.0 of the Yoast SEO plugin

= 1.1.1 =
* Fixed an error where a condition was not properly called only on event singles.

Expand Down

0 comments on commit bcfa9d4

Please sign in to comment.