File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/block-library/ingredient.php
<?php
/**
* Renders the `gtm/ingredient` 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 ingredient.
*/
function gtm_render_block_ingredient( $attr, $content, $block ) {
if ( ! isset( $block->context['gtmRecipeIngredient'] ) ) {
return '';
}
$ingredient = $block->context['gtmRecipeIngredient'];
if ( ! is_array( $ingredient ) || empty( $ingredient ) || empty( $ingredient[0]['items'] ) ) {
return;
}
$inner_html = '';
foreach ( $ingredient as $group ) {
$inner_html .= '<div class="wp-block-gtm-ingredient__group">';
if ( ! empty( $group['label'] ) ) {
$inner_html .= '<div class="wp-block-gtm-ingredient__group-title">';
$inner_html .= esc_html( $group['label'] );
$inner_html .= '</div>';
}
if ( ! empty( $group['items'] ) ) {
$inner_html .= '<ul class="wp-block-gtm-ingredient__group-list">';
foreach ( $group['items'] as $item ) {
$inner_html .= '<li class="wp-block-gtm-ingredient__item">';
$inner_html .= '<span class="wp-block-gtm-ingredient__mark-as-done-container">';
$inner_html .= ' <i class="wp-block-gtm-ingredient__empty-icon gtm-icon gtm-basic-icon-circle-regular"></i>';
$inner_html .= ' <i class="wp-block-gtm-ingredient__marked-icon gtm-icon gtm-basic-icon-check"></i>';
$inner_html .= '</span>';
$inner_html .= sprintf( '<span class="wp-block-gtm-ingredient__item-text">%s</span>', esc_html( $item ) );
$inner_html .= '</li>';
}
$inner_html .= '</ul>';
}
$inner_html .= '</div>';
}
$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );
if ( get_option( 'gtm_seo_enable_post_rich_snippets', true ) ) {
add_filter( 'gtm_ingredient_block_schema', function ( $schema = [] ) use ( $ingredient ) {
foreach ( $ingredient as $group ) {
foreach ( $group['items'] as $item ) {
$schema[] = $item;
}
}
return $schema;
} );
}
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$inner_html
);
}
/**
* Registers the `gtm/ingredient` block on the server.
*/
function gtm_register_block_ingredient() {
gtm_register_block_type( 'ingredient', [
'render_callback' => 'gtm_render_block_ingredient',
] );
}
add_action( 'init', 'gtm_register_block_ingredient', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/ingredient', 'gtm_compile_block_css_ingredient', 10, 3 );
function gtm_compile_block_css_ingredient( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
// Title
gtm_css_compileCssVar( $block_style, "ingredient-title-typography", gtm_css_parseTypographyProps( $attributes['titleTypography'] ) );
gtm_css_compileCssVar( $block_style, "ingredient-title-spacing", gtm_css_parseSpacingValue( $attributes['titleSpacing'] ) );
gtm_css_compileCssVar( $block_style, "ingredient-title-color", gtm_css_parseColorValue( $attributes['titleColor'] ) );
gtm_css_compileCssVar( $block_style, "ingredient-group-spacing", gtm_css_parseSpacingValue( $attributes['groupSpacing'] ) );
// Listing
gtm_css_compileCssVar( $block_style, "ingredient-list-spacing", gtm_css_parseSpacingValue( $attributes['listSpacing'] ) );
// Apply to output
$block_style['style'] = ['{{BLOCK}}' => $block_style['style']];
return [
'classes' => array_merge( $output['classes'], $block_style['classes'] ),
'style' => array_replace_recursive( $output['style'], $block_style['style'] ),
];
}