$fields Field values. * @param WP_Post $post The post. * @param Node_Context $c Page information. * @param Graph $graph The graph. * @return array|null */ public function build( string $type, array $fields, WP_Post $post, Node_Context $c, Graph $graph ): ?array { $item = $this->text( $fields, 'item_name' ); $kind = $this->text( $fields, 'item_type' ); $rating = $this->text( $fields, 'rating_value' ); $best = (int) $this->text( $fields, 'best_rating', '5' ); $worst = (int) $this->text( $fields, 'worst_rating', '1' ); $author = Author_Node::build( (int) $post->post_author ); if ( '' === $item || '' === $kind || '' === $rating || $best <= $worst || (float) $rating < $worst || (float) $rating > $best ) { return null; } // Google wants an author name shorter than 100 characters. if ( null === $author || mb_strlen( (string) $author['name'] ) >= 100 ) { return null; } $graph->add( $author ); return array( '@type' => 'Review', '@id' => $c->id( 'review' ), 'mainEntityOfPage' => array( '@id' => $c->id( 'webpage' ) ), 'itemReviewed' => array( '@type' => $kind, 'name' => $item, 'url' => $this->text( $fields, 'item_url' ), ), 'reviewRating' => array( '@type' => 'Rating', 'ratingValue' => $this->number( $rating ), 'bestRating' => $best, 'worstRating' => $worst, ), 'author' => array( '@id' => $author['@id'] ), 'datePublished' => get_post_time( 'c', false, $post ), 'reviewBody' => $this->text( $fields, 'review_body', trim( wp_strip_all_tags( get_the_excerpt( $post ) ) ) ), 'publisher' => array( '@id' => $c->entity_id() ), ); } }