diff --git a/src/includes/class-wordlift-post-to-jsonld-converter.php b/src/includes/class-wordlift-post-to-jsonld-converter.php index 701e5a189..8ec201150 100644 --- a/src/includes/class-wordlift-post-to-jsonld-converter.php +++ b/src/includes/class-wordlift-post-to-jsonld-converter.php @@ -194,9 +194,18 @@ public function convert( $post_id, &$references = array(), &$references_infos = $post_id ); - // Set the values returned by the filter. - $jsonld['author'] = $ret_val['author']; - $references = $ret_val['references']; + // Set the values returned by the author filter. + /* + * Do not add the author JSON-LD if an invalid author was referenced in a post. + * + * @see https://github.com/insideout10/wordlift-plugin/issues/1728 + * + * @since 3.53.2 + */ + if ( ! empty( $ret_val['author'] ) ) { + $jsonld['author'] = $ret_val['author']; + $references = $ret_val['references']; + } // Return the JSON-LD if filters are disabled by the client. if ( $this->disable_convert_filters ) { @@ -264,9 +273,19 @@ public function get_author( $author_id, &$references ) { // Get the entity bound to this user. $entity_id = $this->user_service->get_entity( $author_id ); - // If there's no entity bound return a simple author structure. - if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) { + if ( ! empty( $entity_id ) && 'publish' === get_post_status( $entity_id ) ) { + // Add the author to the references. + $author_uri = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id ); + $references[] = $entity_id; + + // Return the JSON-LD for the referenced entity. + return array( + '@id' => $author_uri, + ); + } + // If there's no entity bound return a simple author structure. + if ( false !== get_userdata( $author_id ) ) { $author = get_the_author_meta( 'display_name', $author_id ); $author_first_name = get_the_author_meta( 'first_name', $author_id ); $author_last_name = get_the_author_meta( 'last_name', $author_id ); @@ -282,14 +301,8 @@ public function get_author( $author_id, &$references ) { ); } - // Add the author to the references. - $author_uri = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id ); - $references[] = $entity_id; - - // Return the JSON-LD for the referenced entity. - return array( - '@id' => $author_uri, - ); + // No valid entity or author so return empty array + return array(); } /**