get_post_data( $post_id ); if ( empty( $post_data ) ) { return array( '@type' => $this->type ); } $schema = array( '@type' => $this->type, 'name' => $post_data['title'], 'datePublished' => $post_data['date'], ); // Review body from excerpt or content. $schema['reviewBody'] = ! empty( $fields['reviewBody'] ) ? $fields['reviewBody'] : $post_data['excerpt']; // Author. $author = $this->get_author_data( $post_id ); if ( ! empty( $fields['author'] ) ) { $author = $fields['author']; if ( is_string( $author ) ) { $author = array( '@type' => 'Person', 'name' => $author, ); } elseif ( is_array( $author ) && ! isset( $author['@type'] ) ) { $author['@type'] = 'Person'; } } if ( ! empty( $author ) ) { $schema['author'] = $author; } // Review rating. if ( ! empty( $fields['reviewRating'] ) ) { $rating = $fields['reviewRating']; if ( is_numeric( $rating ) ) { $rating = array( '@type' => 'Rating', 'ratingValue' => $rating, 'bestRating' => 5, 'worstRating' => 1, ); } elseif ( is_array( $rating ) && ! isset( $rating['@type'] ) ) { $rating['@type'] = 'Rating'; } $schema['reviewRating'] = $rating; } // Item reviewed. if ( ! empty( $fields['itemReviewed'] ) ) { $item = $fields['itemReviewed']; if ( is_string( $item ) ) { $item = array( '@type' => 'Thing', 'name' => $item, ); } elseif ( is_array( $item ) && ! isset( $item['@type'] ) ) { $item['@type'] = 'Thing'; } $schema['itemReviewed'] = $item; } // Publisher. $publisher = $this->get_publisher_data(); if ( ! empty( $fields['publisher'] ) ) { $publisher = $fields['publisher']; if ( is_string( $publisher ) ) { $publisher = array( '@type' => 'Organization', 'name' => $publisher, ); } elseif ( is_array( $publisher ) && ! isset( $publisher['@type'] ) ) { $publisher['@type'] = 'Organization'; } } if ( ! empty( $publisher ) ) { $schema['publisher'] = $publisher; } // Merge remaining AI-detected fields. $schema = $this->merge_fields( $schema, $fields, array( 'name', 'description', 'image', 'url', ) ); return $schema; } }