File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/block-library/custom-field.php
<?php
/**
* Renders the `gtm/custom-field` 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 custom field for the current post.
*/
function gtm_render_block_custom_field( $attr, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$post_ID = $block->context['postId'];
$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );
$is_display = true;
$inner_html = '';
$metaContent = '';
// No need to get post meta when using alternate text
if ( $attr['metaKey'] && $attr['displayCondition'] != 'display-alt' ) {
$metaContent = get_post_meta( $post_ID, $attr['metaKey'], true );
}
if ( $attr['displayCondition'] == 'display-all' ) {
$is_display = true;
} else if ( $attr['displayCondition'] == 'display-alt' ) {
$metaContent = $attr['altText'];
$is_display = ! empty( $metaContent );
} else if ( $attr['displayCondition'] == 'hidden-empty' && empty( $metaContent ) ) {
$is_display = false;
} else if ( $metaContent == '' ) { // Hide when blank is a default behavior
$is_display = false;
}
if ( $is_display ) {
if ( ! empty( $attr['icon'] ) ) {
$inner_html .= '<i class="gtm-icon ' . $attr['icon'] . '"></i>';
}
if ( ! empty( $attr['label'] ) ) {
$inner_html .= '<span class="wp-block-gtm-custom-field__label">' . $attr['label'] . '</span>';
}
$inner_html .= '<span class="wp-block-gtm-custom-field__content">';
if ( ! empty( $attr['prefix'] ) ) {
$inner_html .= '<span class="wp-block-gtm-custom-field__prefix">' . $attr['prefix'] . '</span>';
}
$inner_html .= ( $metaContent ?? '' );
if ( ! empty( $attr['suffix'] ) ) {
$inner_html .= '<span class="wp-block-gtm-custom-field__suffix">' . $attr['suffix'] . '</span>';
}
$inner_html .= '</span>';
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$inner_html
);
}
}
/**
* Registers the `gtm/custom-field` block on the server.
*/
function gtm_register_block_custom_field() {
gtm_register_block_type( 'custom-field', [
'render_callback' => 'gtm_render_block_custom_field',
] );
}
add_action( 'init', 'gtm_register_block_custom_field', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/custom-field', 'gtm_compile_block_css_custom_field', 10, 3 );
function gtm_compile_block_css_custom_field( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
//Label
gtm_css_compileCssVar( $block_style, "custom-field-label-typography", gtm_css_parseTypographyProps( $attributes['labelTypography'] ) );
gtm_css_compileCssVar( $block_style, "custom-field-label-spacing", gtm_css_parseSpacingValue( $attributes['labelSpacing'] ) );
gtm_css_compileCssVar( $block_style, "custom-field-label-color", gtm_css_parseColorValue( $attributes['labelColor'] ) );
// Icon
gtm_css_compileCssVar( $block_style, "custom-field-icon-size", $attributes['iconSize'] );
gtm_css_compileCssVar( $block_style, "custom-field-icon-width", $attributes['iconWidth'] );
gtm_css_compileCssVar( $block_style, 'custom-field-icon-radius', gtm_css_parseBorderRadiusValue( $attributes['iconRadius'] ) );
gtm_css_compileCssVar( $block_style, "custom-field-icon-spacing", gtm_css_parseSpacingValue( $attributes['iconSpacing'] ) );
gtm_css_compileCssVar( $block_style, "custom-field-icon-color", gtm_css_parseColorValue( $attributes['iconColor'] ) );
gtm_css_compileCssVar( $block_style, "custom-field-icon-bg", gtm_css_parseColorValue( $attributes['iconBg'] ) );
gtm_css_compileCssVar( $block_style, "custom-field-icon-hover-color", gtm_css_parseColorValue( $attributes['iconHoverColor'] ) );
gtm_css_compileCssVar( $block_style, "custom-field-icon-hover-bg", gtm_css_parseColorValue( $attributes['iconHoverBg'] ) );
// 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'] ),
];
}