auto-update-appointment-provider.php
2 months ago
auto-update-appointment-service.php
2 months ago
auto-update-field-value.php
2 months ago
base-field-context-macro.php
2 months ago
base-field-context-macro.php
59 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Shared helpers for JetEngine macros that read JetFormBuilder field values. |
| 4 | * |
| 5 | * @package JFB_Compatibility\Jet_Engine\Macros |
| 6 | */ |
| 7 | |
| 8 | namespace JFB_Compatibility\Jet_Engine\Macros; |
| 9 | |
| 10 | if ( ! defined( 'WPINC' ) ) { |
| 11 | die; |
| 12 | } |
| 13 | |
| 14 | abstract class Base_Field_Context_Macro extends \Jet_Engine_Base_Macros { |
| 15 | |
| 16 | protected function get_context_value( string $field_name ) { |
| 17 | $request_key = 'jfb_update_related_' . $field_name; |
| 18 | |
| 19 | if ( |
| 20 | isset( $GLOBALS['jfb_generator_context'] ) && |
| 21 | is_array( $GLOBALS['jfb_generator_context'] ) && |
| 22 | array_key_exists( $field_name, $GLOBALS['jfb_generator_context'] ) |
| 23 | ) { |
| 24 | return $this->sanitize_value( $GLOBALS['jfb_generator_context'][ $field_name ] ); |
| 25 | } |
| 26 | |
| 27 | if ( isset( $_REQUEST[ $request_key ] ) ) { |
| 28 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 29 | return $this->sanitize_value( wp_unslash( $_REQUEST[ $request_key ] ) ); |
| 30 | } |
| 31 | |
| 32 | if ( isset( $GLOBALS[ $request_key ] ) ) { |
| 33 | return $this->sanitize_value( $GLOBALS[ $request_key ] ); |
| 34 | } |
| 35 | |
| 36 | if ( function_exists( 'jet_fb_context' ) ) { |
| 37 | $request_data = jet_fb_context()->resolve_request(); |
| 38 | |
| 39 | if ( isset( $request_data[ $field_name ] ) ) { |
| 40 | return $this->sanitize_value( $request_data[ $field_name ] ); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return ''; |
| 45 | } |
| 46 | |
| 47 | protected function sanitize_value( $value ) { |
| 48 | if ( is_array( $value ) ) { |
| 49 | return $value; |
| 50 | } |
| 51 | |
| 52 | if ( is_numeric( $value ) ) { |
| 53 | return $value; |
| 54 | } |
| 55 | |
| 56 | return sanitize_text_field( $value ); |
| 57 | } |
| 58 | } |
| 59 |