PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.2.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.2.1
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / includes / blocks / render / calculated-field-render.php

calculated-field-render.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.2.1, at includes/blocks/render/calculated-field-render.php

71 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Jet_Form_Builder\Blocks\Render;
4
5 // If this file is called directly, abort.
6 use Jet_Form_Builder\Classes\Tools;
7 use Jet_Form_Builder\Live_Form;
8
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 /**
14 * Define text field renderer class
15 */
16 class Calculated_Field_Render extends Base {
17
18 public function get_name() {
19 return 'calculated-field';
20 }
21
22 public function render_editor_placeholder() {
23 return Tools::is_editor() ? '25.00' : '0.00';
24 }
25
26 /**
27 * We do not need a <label> tag in any case,
28 * because there is no visual field in this field
29 * that can be referenced through the "for" attribute.
30 *
31 * @see https://github.com/Crocoblock/jetformbuilder/issues/356
32 */
33 protected function get_fields_label_tag(): string {
34 return 'div';
35 }
36
37 /**
38 * Get calulation formula for calculated field
39 *
40 * @return [type] [description]
41 */
42 public function get_calculated_data( $args ) {
43
44 if ( empty( $args['calc_formula'] ) ) {
45 return '';
46 }
47
48 $formula = preg_replace_callback(
49 '/%([a-zA-Z-_]+)::([a-zA-Z0-9-_]+)%/',
50 function ( $matches ) {
51 switch ( strtolower( $matches[1] ) ) {
52 case 'field':
53 return '%' . $matches[2] . '%';
54
55 case 'meta':
56 return get_post_meta( Live_Form::instance()->post->ID, $matches[2], true );
57
58 default:
59 $macros_name = $matches[1];
60
61 return apply_filters( "jet-engine/calculated-data/$macros_name", $matches[0], $matches );
62 }
63 },
64 $args['calc_formula']
65 );
66
67 return str_replace( '^', '**', $formula );
68 }
69
70 }
71