Tell us what you are trying to do?
I'm trying to calculate some fields using a shortcode. The shortcode works, but when I try to edit the Tooset template via the frontend, I get a syntax error. The shortcode works correctly until I edit the Toolset template. I've inserted the shortcode using the WP Snippets plugin.
Is there any documentation that you are following?
https://toolset.com/forums/topic/displaying-a-weight-as-pounds-at-3-and-above-and-ounces-below-3/
Is there a similar example that we can see?
What is the link to your site?
Hi,
Thank you for contacting us and I'd be happy to assist.
Have you tried including the same code snippet through some other method? For example, using Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file?
If the issue persists through other methods, too, I'll need to see how this template and the custom shortcode are being used in the admin area. You can share temporary admin login details, in reply to this message.
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
regards,
Waqar
Thank you for sharing the access details, but I'm getting the incorrect password message.
Can you please check the username and password for the WP admin access again?
(I've set your next reply as private)
Thank you for sharing the access details.
The use of the eval function, which is being used in the current 'calculate' shortcode, is generally not considered safe.
Here is a custom shortcode that you can use instead of to return the BMI value instead:
add_shortcode('custom_show_BMI', 'custom_show_BMI_func');
function custom_show_BMI_func($atts) {
extract( shortcode_atts( array(
'round' => 0,
), $atts ) );
$weight_value = types_render_field('weight', array("output" => "raw"));
$height_value = types_render_field('height', array("output" => "raw"));
if(!empty($weight_value) && !empty($height_value)) {
$BMI = $weight_value/($height_value ** 2);
return round($BMI, $atts['round']);
}
}
Usage Examples:
[custom_show_BMI]
[custom_show_BMI round='2']
[custom_show_BMI round='3']