File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/block-library/review-note.php
<?php
/**
* Renders the `gtm/review-note` 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 review note for the current post.
*/
function gtm_render_block_review_note( $attr, $content, $block ) {
if ( ! isset( $block->context['gtmReviewPros'] ) && ! isset( $block->context['gtmReviewCons'] ) ) {
return '';
}
if ( $attr['type'] == 'pros' ) {
$notes = $block->context['gtmReviewPros'];
add_filter( 'gtm_has_review_note_type_pros', '__return_true' );
} else {
$notes = $block->context['gtmReviewCons'];
add_filter( 'gtm_has_review_note_type_cons', '__return_true' );
}
if ( empty( $notes ) ) {
return '';
}
$inner_html = '<ul class="wp-block-gtm-review-note__list">';
foreach ( $notes as $note ) {
if ( ! empty( trim( $note ) ) ) {
$inner_html .= sprintf( '<li>%s</li>', esc_html( $note ) );
}
}
$inner_html .= '</ul>';
$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );
// Render only when enable schema
if ( get_option( 'gtm_seo_enable_post_rich_snippets', true ) ) {
add_action( 'wp_footer', function () use ( $attr, $notes ) {
gtm_render_block_review_note_schema( [
'type' => $attr['type'],
'notes' => $notes,
] );
} );
}
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$inner_html
);
}
/**
* Registers the `gtm/review-note` block on the server.
*/
function gtm_register_block_review_note() {
gtm_register_block_type( 'review-note', [
'render_callback' => 'gtm_render_block_review_note',
] );
}
add_action( 'init', 'gtm_register_block_review_note', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/review-note', 'gtm_compile_block_css_review_note', 10, 3 );
function gtm_compile_block_css_review_note( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
$block_style['classes'][] = "gtm-has-review-note-bullet-type-{$attributes['bulletType']}";
if ( $attributes['icon'] ) {
$block_style['classes'][] = "gtm-has-review-note-icon-{$attributes['icon']}";
}
if ( $attributes['enableTimeline'] ) {
$block_style['classes'][] = "gtm-has-review-note-timeline";
}
gtm_css_compileCssVar( $block_style, "review-note-spacing", gtm_css_parseSpacingValue( $attributes['listSpacing'] ) );
gtm_css_compileCssVar( $block_style, "review-note-bullet-width", $attributes['bulletWidth'] );
gtm_css_compileCssVar( $block_style, "review-note-bullet-spacing", gtm_css_parseSpacingValue( $attributes['bulletSpacing'] ) );
gtm_css_compileCssVar( $block_style, "review-note-bullet-radius", gtm_css_parseBorderRadiusValue( $attributes['bulletRadius'] ) );
gtm_css_compileCssVar( $block_style, "review-note-bullet-color", gtm_css_parseColorValue( $attributes['bulletColor'] ) );
gtm_css_compileCssVar( $block_style, "review-note-bullet-bg", gtm_css_parseColorValue( $attributes['bulletBg'] ) );
if ( 'numbers' == $attributes['bulletType'] ) {
gtm_css_compileCssVar( $block_style, "review-note-number-start", $attributes['numberStart'] );
}
if ( $attributes['enableTimeline'] ) {
gtm_css_compileCssVar( $block_style, "review-note-timeline-color", gtm_css_parseColorValue( $attributes['timelineColor'] ) );
if ( $attributes['timelineOpacity'] ?? null ) {
gtm_css_compileCssVar( $block_style, "review-note-timeline-opacity", intval( $attributes['timelineOpacity'] ) / 100 );
}
gtm_css_compileCssVar( $block_style, "review-note-timeline-thickness", $attributes['timelineThickness'] );
}
// 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'] ),
];
}
function gtm_render_block_review_note_schema( $attr = [] ) {
$attr = wp_parse_args( $attr, [
'type' => 'pros',
'notes' => [],
] );
// Render
gtm_the_json_ld( gtm_get_item_list_schema( $attr['notes'], [
'id' => '#gtm-review-note-' . $attr['type'],
] ) );
}