File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/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' => ''] );
$inner_html = '';
if ( $attr['metaKey'] ) {
$metaContent = get_post_meta( $post_ID, $attr['metaKey'], true );
}
$should_display = true;
$should_display_alt = false;
if ( $attr['displayCondition'] == 'display-all' ) {
$should_display = true;
} else if ( $attr['displayCondition'] == 'display-alt' ) {
$should_display_alt = true;
$should_display = true;
} else if ( $attr['displayCondition'] == 'hidden-empty' && empty( $metaContent ) ) {
$should_display = false;
} else if ( empty( $metaContent ) ) { // Hide when blank is a defaullt behavior
$should_display = false;
}
if ( $should_display ) {
if ( $should_display_alt ) {
$inner_html .= '<span class="wp-block-gtm-custom-field__content-alt">' . ( $metaContent ?? '' ) . '</span>';
} else {
if ( ! empty( $attr['icon'] ) ) {
$inner_html .= '<i class="gtm-icon ' . $attr['icon'] . '"></i>';
}
if ( ! empty( $attr['prefix'] ) ) {
$inner_html .= '<span class="wp-block-gtm-custom-field__prefix">' . $attr['prefix'] . '</span>';
}
$inner_html .= '<span class="wp-block-gtm-custom-field__content">' . ( $metaContent ?? '' ) . '</span>';
if ( ! empty( $attr['suffix'] ) ) {
$inner_html .= '<span class="wp-block-gtm-custom-field__suffix">' . $attr['suffix'] . '</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';
gtm_css_compileCssVar( $block_style, "custom-field-icon-size", $attributes['iconSize'] );
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'] ) );
// 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'] ),
];
}