Support Forum
Hello,
After updating from MB Block 1.4.2 to 1.5.0, it changed the output from $60 to \$60.
Not sure if it makes a difference but the value is part of a repeatable group.
I tried adding add_filter( 'rwmb_meta_shortcode_secure', '__return_false' ); but this did not help.
What is the best way to go about removing the slashes again? For right now, I just reverted back to 1.4.2.
Thank you!
Hello Johannes,
What is the sub field type that you are using in a cloneable group? And how do you output the subfield value? I test with a WYSIWYG subfield and see the value is output properly. Screenshot https://imgur.com/Ritp8wX
function my_hero_callback( $attributes, $is_preview = false, $post_id = null ) {
// Fields's data.
if ( empty( $attributes['data'] ) ) {
return;
}
$groups = $attributes['block_group'];
foreach ( $groups as $group ) {
echo '<p>' . $group['group_content'] . '</p>';
}
}
Thank you for looking into this. The price field is just a regular text field. Here is the code:
$meta_boxes[] = array(
'id' => 'twt-product-modules',
'title' => 'TWT Product Modules',
'type' => 'block',
'icon' => 'editor-table',
'category' => 'layout',
//'context' => 'side',
'render_template' => get_stylesheet_directory() . '/blocks/twt-product-modules.php',
'supports' => array(
'anchor' => true,
'customClassName' => true,
'align' => ['full','wide'],
),
'fields' => array(
array(
'name' => '',
'id' => 'modules',
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'collapsible' => true,
'default_state' => 'collapsed',
'group_title' => '{name}',
'fields' => array(
array(
'name' => 'Name',
'id' => 'name',
'type' => 'text',
),
array(
'name' => 'Price',
'id' => 'price',
'type' => 'text',
),
array(
'name' => 'Button Label',
'id' => 'btn_label',
'type' => 'text',
),
array(
'name' => 'Module URL',
'id' => 'btn_url',
'type' => 'text',
),
array(
'name' => 'Image',
'id' => 'img',
'desc' => '472 by 306 pixels',
'type' => 'single_image',
)
),
),
)
);
<?php
$attr = $attributes;
if ( empty( $attr['data'] ) ) {
return;
}
// Assign anchor if available
$id = $attr['anchor'] ?? '';
// Custom CSS class name.
$class = trim('twt-product-modules ' . ( $attr['className'] ?? '' ));
if ( ! empty( $attr['align'] ) ) {
$class .= " align{$attr['align']}";
}
if ( ! empty( $attr['data']['modules'] ) ) {
?>
<div<?= empty($id) ? '' : ' id="'.esc_attr($id).'"'; ?><?= empty( $class ) ? '' : ' class="'.esc_attr($class). '"'; ?>>
<ul class="row twt-product-modules-row">
<?php
foreach($attr['data']['modules'] as $module) {
?>
<li class="col-3 col-t-4 col-m-6">
<?php
if(empty($module['btn_url'])) {
?><div class="twt-product-module"><?php
} else {
?><a href="<?= $module['btn_url']; ?>" class="twt-product-module"><?php
}
?>
<?= wp_get_attachment_image($module['img'], 'medium_large', false, array('class' => 'img', 'alt' => '')); ?>
<div class="content">
<h3 class="name"><strong><?= $module['name']; ?><?php if(!empty($module['price'])) { ?>:</strong> <?= $module['price']; ?>
<?php } else { ?>
</strong>
<?php } ?>
</h3>
<?php if(!empty($module['btn_label'])) { ?>
<p class="btn-c"><span class="btn small"><?= $module['btn_label']; ?></span></p>
<?php } ?>
</div>
<?php
if(!empty($module['btn_url'])) {
?></a><?php
} else {
?></div><?php
}
?>
</li>
<?php
}
?>
</ul>
</div>
<?php
}
Also, on a different site, I just ran into the same issue after upgrading to MB Blocks 1.5.0. A \ is added before $ signs. But this time, in my block render callback function. It affected my JS code that is included in the render_callback function (see below for how it added \ before $). After downgrading to MB Blocks 1.4.2 the \$ were no longer added.
<script>
jQuery(function(\$) {
let hccf_dtable = \$('#households-table').DataTable({
Let me know if you need more information.
Hello,
To simplify, please output the subfield value with this code
foreach($attr['data']['modules'] as $module) {
echo $module['price'];
}
if it still doesn't work, please share your site admin account by submitting this contact form https://metabox.io/contact/
I will take a look.
Hi Peter,
Thank you for your patience with my reply, I just created a fresh WordPress install and added MetaBox and MB Blocks 1.5.1.
Then, I added the code below (as a custom plugin) to set up a simple metabox display:
function twt_metabox_io_blocks($meta_boxes) {
$meta_boxes[] = array(
'id' => 'twt-product-module',
'title' => 'TWT Product Module',
'type' => 'block',
'icon' => 'editor-table',
'category' => 'layout',
//'context' => 'side',
'render_callback' => 'twt_render_product_module',
'supports' => array(
'anchor' => true,
'customClassName' => true,
'align' => ['full','wide'],
),
'fields' => array(
array(
'name' => 'Price',
'id' => 'price',
'type' => 'text',
)
)
);
return $meta_boxes;
}
function twt_render_product_module( $attributes): void {
// Fields data.
if ( empty( $attributes['data'] ) ) {
return;
}
// Custom CSS class name.
$class = 'twt-product-module ' . ( $attributes['className'] ?? '' );
if ( ! empty( $attributes['align'] ) ) {
$class .= " align{$attributes['align']}";
}
?>
<div class="<?= trim($class); ?>">
Price in $:
<?php
echo $attributes['data']['price'];
?>
</div>
<?php
}
add_action('rwmb_meta_boxes', 'twt_metabox_io_blocks');
When I enter $99 as the field value, I get the following output: Price in \$: \$99
When I downgrade MB Blocks to version 1.4.2 the backslashes don't show.
I will submit the login credentials through the contact form shortly.
Thank you!