| 1 |
<?php |
| 2 |
/** |
| 3 |
* JetEngine Macro for accessing form field values during auto-update. |
| 4 |
* |
| 5 |
* This macro allows JetEngine Query Builder to access values from form fields |
| 6 |
* when options are being dynamically regenerated via auto-update feature. |
| 7 |
* |
| 8 |
* Usage in JetEngine Query: |
| 9 |
* Use dynamic tag "JFB Auto-Update - Field Value" with field_name parameter |
| 10 |
* in query conditions, meta queries, or tax queries. |
| 11 |
* |
| 12 |
* @package JFB_Compatibility\Jet_Engine\Macros |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace JFB_Compatibility\Jet_Engine\Macros; |
| 16 |
|
| 17 |
// If this file is called directly, abort. |
| 18 |
if ( ! defined( 'WPINC' ) ) { |
| 19 |
die; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Auto_Update_Field_Value class. |
| 24 |
* |
| 25 |
* JetEngine macro that retrieves form field values from the auto-update context. |
| 26 |
* Values are available in scoped $GLOBALS['jfb_generator_context'] and |
| 27 |
* in legacy $_REQUEST / $GLOBALS keys with 'jfb_update_related_' prefix. |
| 28 |
*/ |
| 29 |
class Auto_Update_Field_Value extends Base_Field_Context_Macro { |
| 30 |
|
| 31 |
/** |
| 32 |
* Returns macro tag for JetEngine. |
| 33 |
* |
| 34 |
* @return string |
| 35 |
*/ |
| 36 |
public function macros_tag() { |
| 37 |
return 'jfb_auto_update_field_value'; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns macro name displayed in JetEngine UI. |
| 42 |
* |
| 43 |
* @return string |
| 44 |
*/ |
| 45 |
public function macros_name() { |
| 46 |
return 'JFB Auto-Update - Field Value'; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns macro arguments configuration. |
| 51 |
* |
| 52 |
* @return array |
| 53 |
*/ |
| 54 |
public function macros_args() { |
| 55 |
return array( |
| 56 |
'field_name' => array( |
| 57 |
'label' => __( 'Field Name', 'jet-form-builder' ), |
| 58 |
'type' => 'text', |
| 59 |
'default' => '', |
| 60 |
), |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Macro callback - retrieves field value from request context. |
| 66 |
* |
| 67 |
* Preferred source (scoped): $GLOBALS['jfb_generator_context'][field_name]. |
| 68 |
* Legacy fallback sources: |
| 69 |
* - $_REQUEST['jfb_update_related_' . field_name] |
| 70 |
* - $GLOBALS['jfb_update_related_' . field_name] (set by Get_From_Je_Query::generate_with_context). |
| 71 |
* |
| 72 |
* @param array $args Macro arguments with 'field_name'. |
| 73 |
* |
| 74 |
* @return string|int|array Field value or empty string if not found. |
| 75 |
*/ |
| 76 |
public function macros_callback( $args = array() ) { |
| 77 |
$field_name = ! empty( $args['field_name'] ) ? $args['field_name'] : null; |
| 78 |
|
| 79 |
if ( ! $field_name ) { |
| 80 |
return ''; |
| 81 |
} |
| 82 |
|
| 83 |
return $this->get_context_value( $field_name ); |
| 84 |
} |
| 85 |
} |
| 86 |
|