$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 { $name = $this->text( $fields, 'name', $this->title( $post ) ); $image = $this->image_url( $fields, 'image', $post ); if ( '' === $name || '' === $image ) { return null; } $prep = (int) $this->text( $fields, 'prep_time' ); $cook = (int) $this->text( $fields, 'cook_time' ); $total = (int) $this->text( $fields, 'total_time' ); if ( $total < 1 && $prep > 0 && $cook > 0 ) { $total = $prep + $cook; } $steps = array(); foreach ( Field_Values::split_lines( $this->text( $fields, 'instructions' ) ) as $step ) { $steps[] = array( '@type' => 'HowToStep', 'text' => $step, ); } $calories = $this->text( $fields, 'calories' ); $author = $this->text( $fields, 'author_name' ); return array( '@type' => 'Recipe', '@id' => $c->id( 'recipe' ), 'mainEntityOfPage' => array( '@id' => $c->id( 'webpage' ) ), 'name' => $name, 'image' => array( $image ), 'description' => $this->text( $fields, 'description', $this->description( $post, $c ) ), 'author' => '' !== $author ? array( '@type' => 'Person', 'name' => $author, ) : $this->author( $post, $graph ), 'datePublished' => get_post_time( 'c', false, $post ), 'prepTime' => Field_Values::duration_from_minutes( $prep ), 'cookTime' => Field_Values::duration_from_minutes( $cook ), 'totalTime' => Field_Values::duration_from_minutes( $total ), 'recipeYield' => $this->text( $fields, 'yield' ), 'recipeCategory' => $this->text( $fields, 'category' ), 'recipeCuisine' => $this->text( $fields, 'cuisine' ), 'keywords' => $this->text( $fields, 'keywords' ), 'recipeIngredient' => Field_Values::split_lines( $this->text( $fields, 'ingredients' ) ), 'recipeInstructions' => $steps, 'nutrition' => '' !== $calories ? array( '@type' => 'NutritionInformation', 'calories' => $calories, ) : null, 'aggregateRating' => $this->aggregate_rating( $fields ), ); } }