HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/block-library/recipe.php
<?php

/**
 * Registers the `gtm/recipe` block on the server.
 */
function gtm_register_block_recipe() {
	gtm_register_block_type( 'recipe', [
		'render_callback' => 'gtm_render_block_recipe',
	] );
}

add_action( 'init', 'gtm_register_block_recipe', 20 );

/**
 * Renders the `gtm/recipe` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the recipe.
 */
function gtm_render_block_recipe( $attr, $content, $block ) {
	$wrapper_attributes = get_block_wrapper_attributes();
	$inner_html         = '';

	$template_slug = 'recipe'; // Default template slug
	$template_name = null;

	if ( ! empty( $attr['templateId'] ) ) {
		list( $template_name, $template_slug ) = explode( '//', $attr['templateId'] );
	}

	GTM_Block_Context::begin( $block );
	$inner_html = gtm_do_template_part( $template_slug, $template_name );
	GTM_Block_Context::end();

	// Render only when enable schema
	if ( get_option( 'gtm_seo_enable_post_rich_snippets', true ) ) {
		add_action( 'wp_footer', function () use ( $attr ) {
			gtm_render_block_recipe_schema( [
				'name'        => ! empty( $attr['title'] ) ? $attr['title'] : get_the_title(),
				'images'      => [get_the_post_thumbnail_url()],
				'description' => ! empty( $attr['summary'] ) ? $attr['summary'] : get_the_excerpt(),
			] );
		} );
	}

	if ( empty( $inner_html ) ) {
		return gtm_get_admin_warning( sprintf( esc_html__( 'No template available. Please create a template part named "%s" in the full site editor.', 'gutenmate' ), esc_html( $template_slug ) ) ) . $content;
	} else {
		return $inner_html;
	}
}

function gtm_render_block_recipe_schema( $attr = [] ) {
	$attr = wp_parse_args( $attr, [
		'name'        => '',
		'images'      => [],
		'description' => '',
		'recipeYield' => 1, // Numeric only
	] );

	$schema = [
		"@context"           => "https://schema.org/",
		"@type"              => "Recipe",
		"name"               => $attr['name'],
		"image"              => $attr['images'],
		"description"        => $attr['description'],
		"author"             => [
			'@id' => '#Author',
		],
		"recipeYield"        => $attr['recipeYield'],
		'recipeIngredient'   => apply_filters( 'gtm_ingredient_block_schema', [] ),
		'recipeInstructions' => apply_filters( 'gtm_direction_block_schema', [] ),
		'nutrition'          => apply_filters( 'gtm_nutrition_block_schema', [] ),
	];

	// Render
	gtm_the_json_ld( $schema );
}