| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die(); |
| 6 |
} |
| 7 |
|
| 8 |
function jet_form_builder_init() { |
| 9 |
jet_form_builder()->init_lang(); |
| 10 |
|
| 11 |
add_action( |
| 12 |
'after_setup_theme', |
| 13 |
array( jet_form_builder(), 'init_plugin' ), |
| 14 |
0 |
| 15 |
); |
| 16 |
|
| 17 |
jet_form_builder()->get_modules()->install( new JFB_Modules\Cli\Module() ); |
| 18 |
jet_form_builder()->get_modules()->install( new JFB_Modules\Framework\Module() ); |
| 19 |
|
| 20 |
// Auto-run outstanding DB migrations after a plugin update (see class docblock). |
| 21 |
\Jet_Form_Builder\Migrations\Auto_Migrator::instance()->init_hooks(); |
| 22 |
} |
| 23 |
|
| 24 |
function jet_form_builder() { |
| 25 |
return Jet_Form_Builder\Plugin::instance(); |
| 26 |
} |
| 27 |
|
| 28 |
function jet_fb_render_form( $settings ) { |
| 29 |
return Jet_Form_Builder\Plugin::instance()->blocks->get_form_class()->render_form( $settings ); |
| 30 |
} |
| 31 |
|
| 32 |
function jet_fb_handler(): \Jet_Form_Builder\Form_Handler { |
| 33 |
return jet_form_builder()->form_handler; |
| 34 |
} |
| 35 |
|
| 36 |
function jet_fb_action_handler(): \Jet_Form_Builder\Actions\Action_Handler { |
| 37 |
return jet_fb_handler()->action_handler; |
| 38 |
} |
| 39 |
|
| 40 |
function jet_fb_request_handler(): \Jet_Form_Builder\Request\Request_Handler { |
| 41 |
return jet_fb_handler()->request_handler; |
| 42 |
} |
| 43 |
|
| 44 |
function jet_fb_msg_router_manager( $data = array() ): \Jet_Form_Builder\Form_Messages\Manager { |
| 45 |
return jet_form_builder()->msg_router->get_manager( $data ); |
| 46 |
} |
| 47 |
|
| 48 |
function jet_fb_preset( $form_id = 0 ): \Jet_Form_Builder\Presets\Preset_Manager { |
| 49 |
return \Jet_Form_Builder\Presets\Preset_Manager::instance()->set_form_id( $form_id ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
/** |
| 54 |
* @return false|\Jet_Form_Builder\Admin\Pages\Base_Page|\Jet_Form_Builder\Admin\Single_Pages\Base_Single_Page |
| 55 |
*/ |
| 56 |
function jet_fb_current_page() { |
| 57 |
try { |
| 58 |
return \Jet_Form_Builder\Admin\Pages\Pages_Manager::instance()->get_current(); |
| 59 |
} catch ( \Jet_Form_Builder\Admin\Exceptions\Not_Found_Page_Exception $exception ) { |
| 60 |
return false; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
function jet_fb_live(): \Jet_Form_Builder\Live_Form { |
| 65 |
return \Jet_Form_Builder\Live_Form::instance(); |
| 66 |
} |
| 67 |
|
| 68 |
function jet_fb_live_arg( string $arg_name, $if_empty = false ) { |
| 69 |
return jet_fb_live_args()->argument( $arg_name, $if_empty ); |
| 70 |
} |
| 71 |
|
| 72 |
function jet_fb_live_args(): \Jet_Form_Builder\Classes\Arguments\Form_Arguments { |
| 73 |
return jet_fb_live()->spec_data; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* @return false|\JFB_Modules\Gateways\Base_Gateway|\JFB_Modules\Gateways\Base_Scenario_Gateway |
| 78 |
*/ |
| 79 |
function jet_fb_gateway_current() { |
| 80 |
return \JFB_Modules\Gateways\Module::instance()->get_current_gateway_controller_or_die(); |
| 81 |
} |
| 82 |
|
| 83 |
function jet_fb_events(): \Jet_Form_Builder\Actions\Events_Manager { |
| 84 |
return \Jet_Form_Builder\Actions\Events_Manager::instance(); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Parse dynamic preset |
| 89 |
* If this hasn't json preset |
| 90 |
* it will return the incoming value |
| 91 |
* |
| 92 |
* @param string $value |
| 93 |
* |
| 94 |
* @return mixed|string |
| 95 |
*/ |
| 96 |
function jet_fb_parse_dynamic( string $value ) { |
| 97 |
return ( new \Jet_Form_Builder\Presets\Types\Dynamic_Preset() )->parse_json( $value ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Same as jet_fb_parse_dynamic(), but declares the string as coming from a |
| 102 |
* trusted, admin-authored origin - the form's own post meta / block |
| 103 |
* attributes, which require `edit_post` on the form to write. |
| 104 |
* |
| 105 |
* Only that makes an explicit `restricted: false` in the preset honoured, the |
| 106 |
* way the editor's "Restrict access" toggle promises. Use it ONLY where the |
| 107 |
* value provably comes from the stored form and never from the request: |
| 108 |
* |
| 109 |
* - validation rules (modules/validation/rules-controller.php) |
| 110 |
* - date min/max (includes/classes/date-tools.php) |
| 111 |
* - conditional blocks(includes/blocks/conditional-block/...) |
| 112 |
* - action conditions (includes/actions/conditions/condition-instance.php) |
| 113 |
* - dynamic value (includes/blocks/dynamic-value.php) |
| 114 |
* |
| 115 |
* Anything parsing a submitted field value (Rich_Content) must keep using |
| 116 |
* jet_fb_parse_dynamic(), where the flag is ignored and the permission check |
| 117 |
* always runs. See issues-tracker #20359. |
| 118 |
* |
| 119 |
* @param string $value |
| 120 |
* |
| 121 |
* @return mixed|string |
| 122 |
*/ |
| 123 |
function jet_fb_parse_dynamic_trusted( string $value ) { |
| 124 |
$preset = new \Jet_Form_Builder\Presets\Types\Dynamic_Preset(); |
| 125 |
$preset->trust_restriction_flag( true ); |
| 126 |
|
| 127 |
return $preset->parse_json( $value ); |
| 128 |
} |
| 129 |
|
| 130 |
function jet_fb_parse_macro( $content ): string { |
| 131 |
return jet_fb_handler()->parser->parse_macros( $content ); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* @since 3.1.0 |
| 136 |
*/ |
| 137 |
function jet_fb_context(): \Jet_Form_Builder\Request\Parser_Context { |
| 138 |
return JFB_Modules\Block_Parsers\Module::instance()->get_context(); |
| 139 |
} |
| 140 |
|