PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
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
← All changes | includes/admin/editor.php +577 -499 1.0.3 → 3.6.6 View file →
@@ -1,499 +1,577 @@
1 -<?php
2 -
3 -namespace Jet_Form_Builder\Admin;
4 -
5 -use Jet_Form_Builder\Gateways\Gateway_Manager;
6 -use Jet_Form_Builder\Plugin;
7 -
8 -/**
9 - * Form editor class
10 - * Thanks Tom J Nowell for initial editor idea and inspiration!
11 - */
12 -
13 -// If this file is called directly, abort.
14 -if ( ! defined( 'WPINC' ) ) {
15 - die;
16 -}
17 -
18 -/**
19 - * Define Editor class
20 - */
21 -class Editor {
22 -
23 - public static $index = 0;
24 -
25 - public $allowed_blocks = null;
26 - public $action = null;
27 - public $item_id = null;
28 -
29 - /**
30 - * Set up editor instatnce props
31 - *
32 - * @param array $config [description]
33 - */
34 - public function __construct( $config = array() ) {
35 -
36 - if ( ! empty( $config['allowed_blocks'] ) ) {
37 - $this->allowed_blocks = $config['allowed_blocks'];
38 - }
39 -
40 - if ( ! empty( $config['action'] ) ) {
41 - $this->action = $config['action'];
42 - }
43 -
44 - if ( ! empty( $config['item_id'] ) ) {
45 - $this->item_id = $config['item_id'];
46 - }
47 -
48 - }
49 -
50 - /**
51 - * Returns action URL
52 - *
53 - * @return [type] [description]
54 - */
55 - public function get_action() {
56 -
57 - if ( null === $this->action ) {
58 - $this->action = apply_filters( 'jet-form-builder/editor/action', null );
59 - }
60 -
61 - return $this->action;
62 -
63 - }
64 -
65 - /**
66 - * Returns current item ID
67 - *
68 - * @return [type] [description]
69 - */
70 - public function get_item_id() {
71 - return $this->item_id;
72 - }
73 -
74 - /**
75 - * Retuns allowed blocks list
76 - *
77 - * @return array
78 - */
79 - public function get_allowed_blocks() {
80 -
81 - if ( empty( $this->allowed_blocks ) ) {
82 -
83 - $this->allowed_blocks = apply_filters( 'jet-form-builder/editor/allowed-blocks', array(
84 - 'core/paragraph',
85 - 'core/image',
86 - 'core/heading',
87 - 'core/verse',
88 - 'core/freeform',
89 - 'core/spacer',
90 - 'core/subhead',
91 - 'core/pullquote',
92 - 'core/preformatted',
93 - 'core/shortcode',
94 - 'core/code',
95 - 'core/quote',
96 - 'core/list',
97 - 'core/heading',
98 - 'core/separator',
99 - 'core/text-columns',
100 - 'core/embed',
101 - 'core-embed/youtube',
102 - 'core-embed/twitter',
103 - 'core-embed/vimeo',
104 - 'core/columns',
105 - 'core/column',
106 - ) );
107 -
108 - }
109 -
110 - return $this->allowed_blocks;
111 - }
112 -
113 - /**
114 - * Returns taxonomies list for the config
115 - * @return [type] [description]
116 - */
117 - public function get_taxonomies_list() {
118 -
119 - $taxonomies = get_taxonomies( array(), 'objects' );
120 -
121 - $result = array();
122 -
123 - foreach ( $taxonomies as $tax ) {
124 - $result[] = array(
125 - 'value' => $tax->name,
126 - 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
127 - );
128 - }
129 -
130 - return $result;
131 -
132 - }
133 -
134 - public function get_preset_config() {
135 - return apply_filters( 'jet-form-builder/editor/preset-config', array(
136 - 'global_fields' => array(
137 - array(
138 - 'name' => 'from',
139 - 'label' => __( 'Source:', 'jet-form-builder' ),
140 - 'type' => 'select',
141 - 'options' => array(
142 - array(
143 - 'value' => '',
144 - 'label' => __( 'Select...', 'jet-form-builder' ),
145 - ),
146 - array(
147 - 'value' => 'post',
148 - 'label' => __( 'Post', 'jet-form-builder' ),
149 - ),
150 - array(
151 - 'value' => 'user',
152 - 'label' => __( 'User', 'jet-form-builder' ),
153 - ),
154 - )
155 - ),
156 - array(
157 - 'name' => 'post_from',
158 - 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
159 - 'type' => 'select',
160 - 'options' => array(
161 - array(
162 - 'value' => 'current_post',
163 - 'label' => __( 'Current post', 'jet-form-builder' ),
164 - ),
165 - array(
166 - 'value' => 'query_var',
167 - 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
168 - ),
169 - ),
170 - 'condition' => array(
171 - 'field' => 'from',
172 - 'value' => 'post',
173 - ),
174 - ),
175 - array(
176 - 'name' => 'user_from',
177 - 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
178 - 'type' => 'select',
179 - 'options' => array(
180 - array(
181 - 'value' => 'current_user',
182 - 'label' => __( 'Current user', 'jet-form-builder' ),
183 - ),
184 - array(
185 - 'value' => 'query_var',
186 - 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
187 - ),
188 - ),
189 - 'condition' => array(
190 - 'field' => 'from',
191 - 'value' => 'user',
192 - ),
193 - ),
194 - array(
195 - 'name' => 'query_var',
196 - 'label' => __( 'Query variable name:', 'jet-form-builder' ),
197 - 'type' => 'text',
198 - 'custom_condition' => 'query_var',
199 - )
200 - ),
201 - 'map_fields' => array(
202 - array(
203 - 'name' => 'key',
204 - 'label' => __( 'Query variable key', 'jet-form-builder' ),
205 - 'type' => 'text',
206 - 'parent_condition' => array(
207 - 'field' => 'from',
208 - 'value' => 'query_vars'
209 - ),
210 - ),
211 - array(
212 - 'name' => 'prop',
213 - 'label' => __( 'Post property', 'jet-form-builder' ),
214 - 'type' => 'select',
215 - 'options' => array(
216 - array(
217 - 'value' => '',
218 - 'label' => __( '--', 'jet-form-builder' ),
219 - ),
220 - array(
221 - 'value' => 'ID',
222 - 'label' => __( 'Post ID', 'jet-form-builder' ),
223 - ),
224 - array(
225 - 'value' => 'post_title',
226 - 'label' => __( 'Post Title', 'jet-form-builder' ),
227 - ),
228 - array(
229 - 'value' => 'post_content',
230 - 'label' => __( 'Post Content', 'jet-form-builder' ),
231 - ),
232 - array(
233 - 'value' => 'post_excerpt',
234 - 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
235 - ),
236 - array(
237 - 'value' => 'post_thumb',
238 - 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
239 - ),
240 - array(
241 - 'value' => 'post_meta',
242 - 'label' => __( 'Post Meta', 'jet-form-builder' ),
243 - ),
244 - array(
245 - 'value' => 'post_terms',
246 - 'label' => __( 'Post Terms', 'jet-form-builder' ),
247 - ),
248 - ),
249 - 'parent_condition' => array(
250 - 'field' => 'from',
251 - 'value' => 'post'
252 - ),
253 - ),
254 - array(
255 - 'name' => 'key',
256 - 'label' => __( 'Taxonomy', 'jet-form-builder' ),
257 - 'type' => 'select',
258 - 'options' => array_merge( array(
259 - array(
260 - 'value' => '',
261 - 'label' => __( 'Select taxonomy...', 'jet-form-builder' ),
262 - )
263 - ), $this->get_taxonomies_list() ),
264 - 'parent_condition' => array(
265 - 'field' => 'from',
266 - 'value' => 'post'
267 - ),
268 - 'condition' => array(
269 - 'field' => 'prop',
270 - 'value' => 'post_terms'
271 - ),
272 - ),
273 - array(
274 - 'name' => 'key',
275 - 'label' => __( 'Meta field key', 'jet-form-builder' ),
276 - 'type' => 'text',
277 - 'parent_condition' => array(
278 - 'field' => 'from',
279 - 'value' => 'post'
280 - ),
281 - 'condition' => array(
282 - 'field' => 'prop',
283 - 'value' => 'post_meta'
284 - ),
285 - ),
286 - array(
287 - 'name' => 'prop',
288 - 'label' => __( 'User field', 'jet-form-builder' ),
289 - 'type' => 'select',
290 - 'options' => array(
291 - array(
292 - 'value' => '',
293 - 'label' => __( '--', 'jet-form-builder' ),
294 - ),
295 - array(
296 - 'value' => 'ID',
297 - 'label' => __( 'User ID', 'jet-form-builder' ),
298 - ),
299 - array(
300 - 'value' => 'login',
301 - 'label' => __( 'User Login', 'jet-form-builder' ),
302 - ),
303 - array(
304 - 'value' => 'email',
305 - 'label' => __( 'Email', 'jet-form-builder' ),
306 - ),
307 - array(
308 - 'value' => 'password',
309 - 'label' => __( 'Password', 'jet-form-builder' ),
310 - ),
311 - array(
312 - 'value' => 'first_name',
313 - 'label' => __( 'First Name', 'jet-form-builder' ),
314 - ),
315 - array(
316 - 'value' => 'last_name',
317 - 'label' => __( 'Last Name', 'jet-form-builder' ),
318 - ),
319 - array(
320 - 'value' => 'user_url',
321 - 'label' => __( 'User URL', 'jet-form-builder' ),
322 - ),
323 - array(
324 - 'value' => 'user_meta',
325 - 'label' => __( 'User Meta', 'jet-form-builder' ),
326 - ),
327 - ),
328 - 'parent_condition' => array(
329 - 'field' => 'from',
330 - 'value' => 'user'
331 - ),
332 - ),
333 - array(
334 - 'name' => 'key',
335 - 'label' => __( 'Meta field key', 'jet-form-builder' ),
336 - 'type' => 'text',
337 - 'parent_condition' => array(
338 - 'field' => 'from',
339 - 'value' => 'user'
340 - ),
341 - 'condition' => array(
342 - 'field' => 'prop',
343 - 'value' => 'user_meta'
344 - ),
345 - ),
346 - ),
347 - ) );
348 - }
349 -
350 - public function get_messages_default() {
351 - return Plugin::instance()->post_type->get_messages_default();
352 - }
353 -
354 - public function get_recaptcha_labels() {
355 - return array(
356 - 'enabled' => __( 'Enable reCAPTCHA v3 form verification', 'jet-form-builder' ),
357 - 'key' => __( 'Site Key:', 'jet-form-builder' ),
358 - 'secret' => __( 'Secret Key:', 'jet-form-builder' ),
359 - );
360 - }
361 -
362 - /**
363 - * Enqueue editor assets
364 - *
365 - * @return void
366 - */
367 - public function enqueue_assets() {
368 -
369 - $handle = 'jet-form-builder';
370 -
371 - do_action( 'jet-form-builder/editor-assets/before', $this, $handle );
372 -
373 - wp_enqueue_script(
374 - $handle,
375 - JET_FORM_BUILDER_URL . 'assets/js/editor.js',
376 - array(
377 - 'wp-editor',
378 - 'wp-core-data',
379 - 'wp-data',
380 - 'wp-block-library',
381 - 'wp-format-library',
382 - 'wp-api-fetch',
383 - ),
384 - JET_FORM_BUILDER_VERSION,
385 - true
386 - );
387 -
388 - wp_enqueue_style(
389 - $handle,
390 - JET_FORM_BUILDER_URL . 'assets/css/editor.css',
391 - array(
392 - 'media',
393 - 'l10n',
394 - 'buttons',
395 - 'wp-edit-blocks',
396 - 'wp-editor',
397 - ),
398 - JET_FORM_BUILDER_VERSION,
399 - 'all'
400 - );
401 -
402 -
403 - wp_localize_script( $handle, 'JetFormEditorData', array(
404 - 'allowedBlocks' => $this->get_allowed_blocks(),
405 - 'action' => $this->get_action(),
406 - 'itemID' => $this->get_item_id(),
407 - 'presetConfig' => $this->get_preset_config(),
408 - 'messagesDefault' => $this->get_messages_default(),
409 - 'recaptchaLabels' => $this->get_recaptcha_labels(),
410 - 'gateways' => $this->get_gateways_data(),
411 - ) );
412 -
413 - do_action( 'jet-form-builder/editor-assets/after', $this, $handle );
414 - }
415 -
416 - private function get_gateways_data() {
417 - $result = array(
418 - 'allowed' => Plugin::instance()->post_type->allow_gateways
419 - );
420 -
421 - if ( $result['allowed'] ) {
422 -
423 - $result['list'] = Gateway_Manager::instance()->get_gateways_for_js();
424 - $result['messages'] = array(
425 - 'success' => 'Payment success message',
426 - 'failed' => 'Payment failed message',
427 - );
428 - }
429 -
430 - return $result;
431 - }
432 -
433 - public function enqueue_form_assets() {
434 -
435 - $handle = 'jet-form-builder/form';
436 -
437 - do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
438 -
439 - wp_enqueue_script(
440 - $handle,
441 - JET_FORM_BUILDER_URL . 'assets/js/form-block.js',
442 - array(
443 - 'wp-editor',
444 - 'wp-core-data',
445 - 'wp-data',
446 - 'wp-block-library',
447 - 'wp-format-library',
448 - 'wp-api-fetch',
449 - ),
450 - JET_FORM_BUILDER_VERSION,
451 - true
452 - );
453 -
454 - wp_enqueue_style(
455 - 'jet-form-builder-others',
456 - Plugin::instance()->plugin_url( 'assets/css/frontend.css' ),
457 - array(),
458 - Plugin::instance()->get_version()
459 - );
460 -
461 - wp_localize_script( $handle, 'JetFormEditorData', array(
462 - 'allowedBlocks' => $this->get_allowed_blocks(),
463 - 'action' => $this->get_action(),
464 - 'itemID' => $this->get_item_id(),
465 - 'presetConfig' => $this->get_preset_config(),
466 - ) );
467 -
468 - do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
469 -
470 - }
471 -
472 - /**
473 - * Render new editor instance
474 - *
475 - * @return [type] [description]
476 - */
477 - public function render( $input_name = '', $content = '', $form_name = '' ) {
478 -
479 - if ( ! $input_name ) {
480 - $input_name = 'jet_form_editor_' . self::$index;
481 - self::$index ++;
482 - }
483 -
484 - ?>
485 - <input name="<?php echo esc_attr( $input_name ); ?>" id="<?php echo esc_attr( $input_name ); ?>" type="hidden"/>
486 - <script>
487 - document.addEventListener( 'jet-form-builder-initialized', function ( event ) {
488 - window.JetFormEditor(
489 - '<?php echo esc_js( $input_name ); ?>',
490 - '<?php echo esc_js( $input_name ); ?>',
491 - '<?php echo html_entity_decode( esc_js( $content ) ); ?>',
492 - '<?php echo esc_js( $form_name ); ?>'
493 - );
494 - } );
495 - </script>
496 - <?php
497 - }
498 -
499 -}
1 +<?php
2 +
3 +namespace Jet_Form_Builder\Admin;
4 +
5 +use Jet_Form_Builder\Actions\Conditions\Condition_Manager as Action_Condition_Manager;
6 +use Jet_Form_Builder\Admin\Pages\Pages_Manager;
7 +use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager;
8 +use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
9 +use Jet_Form_Builder\Classes\Http\Utm_Url;
10 +use Jet_Form_Builder\Classes\Tools;
11 +use Jet_Form_Builder\Exceptions\Repository_Exception;
12 +use Jet_Form_Builder\Plugin;
13 +use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Manager as Block_Condition_Manager;
14 +use JFB_Modules\Post_Type\Module;
15 +
16 +// If this file is called directly, abort.
17 +if ( ! defined( 'WPINC' ) ) {
18 + die;
19 +}
20 +
21 +/**
22 + * Define Editor class
23 + */
24 +class Editor {
25 +
26 + const EDITOR_HANDLE = 'jet-form-builder-editor';
27 + const EDITOR_PACKAGE_HANDLE = 'jet-form-builder-editor-package';
28 +
29 + public function __construct() {
30 + add_action( 'enqueue_block_editor_assets', array( $this, 'admin_assets' ) );
31 + }
32 +
33 + /**
34 + * Register admin assets
35 + *
36 + * @return void [type] [description]
37 + */
38 + public function admin_assets() {
39 + if ( jet_form_builder()->post_type->is_form_editor ) {
40 + $this->enqueue_assets();
41 + } else {
42 + $this->enqueue_form_assets();
43 + }
44 + }
45 +
46 + /**
47 + * Returns taxonomies list for the config
48 + *
49 + * @return [type] [description]
50 + */
51 + public function get_taxonomies_list() {
52 +
53 + $taxonomies = get_taxonomies( array(), 'objects' );
54 +
55 + $result = array();
56 +
57 + foreach ( $taxonomies as $tax ) {
58 + $result[] = array(
59 + 'value' => $tax->name,
60 + 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
61 + );
62 + }
63 +
64 + return $result;
65 + }
66 +
67 + public function get_preset_config() {
68 + return apply_filters(
69 + 'jet-form-builder/editor/preset-config',
70 + array(
71 + 'global_fields' => array(
72 + array(
73 + 'name' => 'from',
74 + 'label' => __( 'Source:', 'jet-form-builder' ),
75 + 'type' => 'select',
76 + 'options' => Tools::with_placeholder(
77 + array(
78 + array(
79 + 'value' => 'post',
80 + 'label' => __( 'Post', 'jet-form-builder' ),
81 + ),
82 + array(
83 + 'value' => 'user',
84 + 'label' => __( 'User', 'jet-form-builder' ),
85 + ),
86 + array(
87 + 'value' => 'query_var',
88 + 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
89 + ),
90 + array(
91 + 'value' => 'term',
92 + 'label' => __( 'Term', 'jet-form-builder' ),
93 + ),
94 + array(
95 + 'value' => 'form_record',
96 + 'label' => __( 'JetFormBuilder Record', 'jet-form-builder' ),
97 + ),
98 + )
99 + ),
100 + ),
101 + array(
102 + 'name' => 'record_query_var',
103 + 'label' => __( 'Record ID query variable:', 'jet-form-builder' ),
104 + 'type' => 'text',
105 + 'condition' => array(
106 + 'field' => 'from',
107 + 'value' => 'form_record',
108 + ),
109 + ),
110 + array(
111 + 'name' => 'post_from',
112 + 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
113 + 'type' => 'select',
114 + 'options' => Tools::with_placeholder(
115 + array(
116 + array(
117 + 'value' => 'current_post',
118 + 'label' => __( 'Current post', 'jet-form-builder' ),
119 + ),
120 + array(
121 + 'value' => 'query_var',
122 + 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
123 + ),
124 + )
125 + ),
126 + 'condition' => array(
127 + 'field' => 'from',
128 + 'value' => 'post',
129 + ),
130 + ),
131 + array(
132 + 'name' => 'user_from',
133 + 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
134 + 'type' => 'select',
135 + 'options' => Tools::with_placeholder(
136 + array(
137 + array(
138 + 'value' => 'current_user',
139 + 'label' => __( 'Current user', 'jet-form-builder' ),
140 + ),
141 + array(
142 + 'value' => 'queried_user',
143 + 'label' => __( 'Queried user', 'jet-form-builder' ),
144 + ),
145 + array(
146 + 'value' => 'query_var',
147 + 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
148 + ),
149 + )
150 + ),
151 + 'condition' => array(
152 + 'field' => 'from',
153 + 'value' => 'user',
154 + ),
155 + ),
156 + array(
157 + 'name' => 'term_from',
158 + 'label' => __( 'Get term from:', 'jet-form-builder' ),
159 + 'type' => 'select',
160 + 'options' => Tools::with_placeholder(
161 + array(
162 + array(
163 + 'value' => 'current_term',
164 + 'label' => __( 'Current term', 'jet-form-builder' ),
165 + ),
166 + array(
167 + 'value' => 'query_var',
168 + 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
169 + ),
170 + )
171 + ),
172 + 'condition' => array(
173 + 'field' => 'from',
174 + 'value' => 'term',
175 + ),
176 + ),
177 + array(
178 + 'name' => 'term_taxonomy',
179 + 'label' => __( 'Term taxonomy', 'jet-form-builder' ),
180 + 'type' => 'select',
181 + 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
182 + 'parent_condition' => array(
183 + 'field' => 'from',
184 + 'value' => 'term',
185 + ),
186 + 'condition' => array(
187 + 'field' => 'term_from',
188 + 'value' => 'query_var',
189 + ),
190 + ),
191 + array(
192 + 'name' => 'query_var',
193 + 'label' => __( 'Query variable name:', 'jet-form-builder' ),
194 + 'type' => 'text',
195 + 'custom_condition' => 'query_var',
196 + 'position' => 'dynamic',
197 + ),
198 + ),
199 + 'map_fields' => array(
200 + array(
201 + 'name' => 'key',
202 + 'label' => __( 'Query variable key', 'jet-form-builder' ),
203 + 'type' => 'text',
204 + 'position' => 'general',
205 + 'parent_condition' => array(
206 + 'field' => 'from',
207 + 'value' => 'query_var',
208 + ),
209 + ),
210 + array(
211 + 'name' => 'prop',
212 + 'label' => __( 'Post property', 'jet-form-builder' ),
213 + 'type' => 'select',
214 + 'options' => Tools::with_placeholder(
215 + array(
216 + array(
217 + 'value' => 'ID',
218 + 'label' => __( 'Post ID', 'jet-form-builder' ),
219 + ),
220 + array(
221 + 'value' => 'post_title',
222 + 'label' => __( 'Post Title', 'jet-form-builder' ),
223 + ),
224 + array(
225 + 'value' => 'post_content',
226 + 'label' => __( 'Post Content', 'jet-form-builder' ),
227 + ),
228 + array(
229 + 'value' => 'post_status',
230 + 'label' => __( 'Post Status', 'jet-form-builder' ),
231 + ),
232 + array(
233 + 'value' => 'post_author',
234 + 'label' => __( 'Post Author', 'jet-form-builder' ),
235 + ),
236 + array(
237 + 'value' => 'post_excerpt',
238 + 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
239 + ),
240 + array(
241 + 'value' => 'post_date',
242 + 'label' => __( 'Post Date', 'jet-form-builder' ),
243 + ),
244 + array(
245 + 'value' => 'post_date_gmt',
246 + 'label' => __( 'Post Date GMT', 'jet-form-builder' ),
247 + ),
248 + array(
249 + 'value' => 'post_thumb',
250 + 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
251 + ),
252 + array(
253 + 'value' => 'post_meta',
254 + 'label' => __( 'Post Meta', 'jet-form-builder' ),
255 + ),
256 + array(
257 + 'value' => 'post_terms',
258 + 'label' => __( 'Post Terms', 'jet-form-builder' ),
259 + ),
260 + )
261 + ),
262 + 'parent_condition' => array(
263 + 'field' => 'from',
264 + 'value' => 'post',
265 + ),
266 + ),
267 + array(
268 + 'name' => 'key',
269 + 'label' => __( 'Taxonomy', 'jet-form-builder' ),
270 + 'type' => 'select',
271 + 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
272 + 'parent_condition' => array(
273 + 'field' => 'from',
274 + 'value' => 'post',
275 + ),
276 + 'condition' => array(
277 + 'field' => 'prop',
278 + 'value' => 'post_terms',
279 + ),
280 + ),
281 + array(
282 + 'name' => 'key',
283 + 'label' => __( 'Meta field key', 'jet-form-builder' ),
284 + 'type' => 'text',
285 + 'parent_condition' => array(
286 + 'field' => 'from',
287 + 'value' => 'post',
288 + ),
289 + 'condition' => array(
290 + 'field' => 'prop',
291 + 'value' => 'post_meta',
292 + ),
293 + ),
294 + array(
295 + 'name' => 'prop',
296 + 'label' => __( 'User field', 'jet-form-builder' ),
297 + 'type' => 'select',
298 + 'options' => Tools::with_placeholder(
299 + array(
300 + array(
301 + 'value' => 'ID',
302 + 'label' => __( 'User ID', 'jet-form-builder' ),
303 + ),
304 + array(
305 + 'value' => 'user_login',
306 + 'label' => __( 'User Login', 'jet-form-builder' ),
307 + ),
308 + array(
309 + 'value' => 'user_email',
310 + 'label' => __( 'Email', 'jet-form-builder' ),
311 + ),
312 + array(
313 + 'value' => 'password',
314 + 'label' => __( 'Password', 'jet-form-builder' ),
315 + ),
316 + array(
317 + 'value' => 'first_name',
318 + 'label' => __( 'First Name', 'jet-form-builder' ),
319 + ),
320 + array(
321 + 'value' => 'last_name',
322 + 'label' => __( 'Last Name', 'jet-form-builder' ),
323 + ),
324 + array(
325 + 'value' => 'display_name',
326 + 'label' => __( 'Display Name', 'jet-form-builder' ),
327 + ),
328 + array(
329 + 'value' => 'user_url',
330 + 'label' => __( 'User URL', 'jet-form-builder' ),
331 + ),
332 + array(
333 + 'value' => 'user_meta',
334 + 'label' => __( 'User Meta', 'jet-form-builder' ),
335 + ),
336 + )
337 + ),
338 + 'parent_condition' => array(
339 + 'field' => 'from',
340 + 'value' => 'user',
341 + ),
342 + ),
343 + array(
344 + 'name' => 'key',
345 + 'label' => __( 'Meta field key', 'jet-form-builder' ),
346 + 'type' => 'text',
347 + 'parent_condition' => array(
348 + 'field' => 'from',
349 + 'value' => 'user',
350 + ),
351 + 'condition' => array(
352 + 'field' => 'prop',
353 + 'value' => 'user_meta',
354 + ),
355 + ),
356 + array(
357 + 'name' => 'prop',
358 + 'label' => __( 'Term property', 'jet-form-builder' ),
359 + 'type' => 'select',
360 + 'options' => Tools::with_placeholder(
361 + array(
362 + array(
363 + 'value' => 'term_id',
364 + 'label' => __( 'Term ID', 'jet-form-builder' ),
365 + ),
366 + array(
367 + 'value' => 'name',
368 + 'label' => __( 'Name', 'jet-form-builder' ),
369 + ),
370 + array(
371 + 'value' => 'slug',
372 + 'label' => __( 'Slug', 'jet-form-builder' ),
373 + ),
374 + array(
375 + 'value' => 'parent',
376 + 'label' => __( 'Parent', 'jet-form-builder' ),
377 + ),
378 + array(
379 + 'value' => 'term_meta',
380 + 'label' => __( 'Term Meta', 'jet-form-builder' ),
381 + ),
382 + )
383 + ),
384 + 'parent_condition' => array(
385 + 'field' => 'from',
386 + 'value' => 'term',
387 + ),
388 + ),
389 + array(
390 + 'name' => 'key',
391 + 'label' => __( 'Meta field key', 'jet-form-builder' ),
392 + 'type' => 'text',
393 + 'parent_condition' => array(
394 + 'field' => 'from',
395 + 'value' => 'term',
396 + ),
397 + 'condition' => array(
398 + 'field' => 'prop',
399 + 'value' => 'term_meta',
400 + ),
401 + ),
402 + ),
403 + )
404 + );
405 + }
406 +
407 + /**
408 + * Enqueue editor assets
409 + *
410 + * @return void
411 + * @throws Repository_Exception
412 + */
413 + public function enqueue_assets() {
414 + $script_asset = require_once jet_form_builder()->plugin_dir( 'assets/build/editor/package.asset.php' );
415 +
416 + if ( true === $script_asset ) {
417 + return;
418 + }
419 +
420 + do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
421 +
422 + array_push(
423 + $script_asset['dependencies'],
424 + 'jet-fb-components',
425 + 'jet-fb-data',
426 + 'jet-fb-actions-v2',
427 + 'jet-fb-blocks-v2-to-actions-v2'
428 + );
429 + wp_enqueue_style( 'jet-fb-components' );
430 +
431 + wp_enqueue_script(
432 + self::EDITOR_PACKAGE_HANDLE,
433 + Plugin::instance()->plugin_url( 'assets/build/editor/package.js' ),
434 + $script_asset['dependencies'],
435 + $script_asset['version'],
436 + true
437 + );
438 +
439 + wp_localize_script(
440 + self::EDITOR_PACKAGE_HANDLE,
441 + 'jetFormEvents',
442 + jet_fb_events()->to_array()
443 + );
444 +
445 + wp_localize_script(
446 + self::EDITOR_PACKAGE_HANDLE,
447 + 'jetFormBlockConditions',
448 + Block_Condition_Manager::instance()->to_array()
449 + );
450 +
451 + wp_set_script_translations(
452 + self::EDITOR_PACKAGE_HANDLE,
453 + 'jet-form-builder',
454 + Plugin::instance()->plugin_dir( 'languages' )
455 + );
456 +
457 + $script_asset = require_once jet_form_builder()->plugin_dir( 'assets/build/editor/form.builder.asset.php' );
458 +
459 + do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
460 +
461 + wp_enqueue_script(
462 + self::EDITOR_HANDLE,
463 + Plugin::instance()->plugin_url( 'assets/build/editor/form.builder.js' ),
464 + $script_asset['dependencies'],
465 + $script_asset['version'],
466 + true
467 + );
468 +
469 + wp_enqueue_style(
470 + self::EDITOR_HANDLE,
471 + Plugin::instance()->plugin_url( 'assets/build/editor/form.builder.css' ),
472 + array(
473 + 'media',
474 + 'l10n',
475 + 'buttons',
476 + 'wp-edit-blocks',
477 + 'wp-editor',
478 + ),
479 + $script_asset['version']
480 + );
481 +
482 + $conditions_settings = ( new Action_Condition_Manager() )->get_settings();
483 + $exclude_events = array(
484 + 'redirect_to_page' => array( 'WC.ORDER.COMPLETE', 'WC.CHECKOUT.COMPLETE' ),
485 + );
486 +
487 + /** @var Module $post_type */
488 + /** @noinspection PhpUnhandledExceptionInspection */
489 + $post_type = jet_form_builder()->module( 'post-type' );
490 +
491 + $utm = new Utm_Url( 'plugin' );
492 + $utm->set_medium( 'editor' );
493 + $utm->set_content( $utm->get_license_and_theme() );
494 +
495 + $addons = JET_FORM_BUILDER_SITE . '/addons/';
496 + $pricing = JET_FORM_BUILDER_SITE . '/pricing/';
497 +
498 + wp_localize_script(
499 + self::EDITOR_PACKAGE_HANDLE,
500 + 'JetFormEditorData',
501 + apply_filters(
502 + 'jet-form-builder/editor/config',
503 + array(
504 + 'presetConfig' => $this->get_preset_config(),
505 + 'messagesDefault' => $post_type->get_messages(),
506 + 'helpForRepeaters' => $this->get_help_for_repeaters(),
507 + 'global_settings' => Tab_Handler_Manager::instance()->all(),
508 + 'global_settings_url' => Pages_Manager::instance()->get_stable_url( 'jfb-settings' ),
509 + 'jetEngineVersion' => Tools::get_jet_engine_version(),
510 + 'actionConditionSettings' => $conditions_settings,
511 + 'actionConditionExcludeEvents' => $exclude_events,
512 + 'argumentsSource' => Form_Arguments::get_options(),
513 + 'utmLinks' => array(
514 + 'allProActions' => $utm->set_campaign( 'jetform-settings/pro-actions' )->add_query( $addons ),
515 + 'limitResponses' => $utm->set_campaign( 'jetform-settings/limit-form-responses' )->add_query( $pricing ),
516 + 'scheduleForm' => $utm->set_campaign( 'jetform-settings/schedule-forms' )->add_query( $pricing ),
517 + 'userLoginPattern' => $utm->set_campaign( 'welcome-block/user-login' )->add_query( $addons . 'user-login/' ),
518 + 'resetPassPattern' => $utm->set_campaign( 'welcome-block/reset-password' )->add_query( $addons . 'user-login/' ),
519 + ),
520 + 'isActivePro' => jet_form_builder()->addons_manager->is_active(),
521 + 'assetsUrl' => jet_form_builder()->plugin_url( 'assets/' ),
522 + )
523 + )
524 + );
525 +
526 + do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
527 + }
528 +
529 + private function get_help_for_repeaters() {
530 + return array(
531 + 'conditional_block' => array(
532 + 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
533 + ),
534 + 'conditional_block_or' => array(
535 + 'label' => __( 'With many conditions for the block, they are checked with the OR operator', 'jet-form-builder' ),
536 + ),
537 + 'conditional_action' => array(
538 + 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
539 + ),
540 + 'conditional_action_or' => array(
541 + 'label' => __( 'With many conditions for the action, they are checked with the OR operator', 'jet-form-builder' ),
542 + ),
543 + );
544 + }
545 +
546 + public function enqueue_form_assets() {
547 +
548 + $handle = 'jet-form-builder/form';
549 +
550 + do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
551 +
552 + // todo: refactor with new way of assets loading
553 + wp_register_script(
554 + $handle,
555 + Plugin::instance()->plugin_url( 'assets/build/editor/default.builder.js' ),
556 + array(
557 + 'wp-core-data',
558 + 'wp-data',
559 + 'wp-block-library',
560 + 'wp-format-library',
561 + 'wp-api-fetch',
562 + ),
563 + JET_FORM_BUILDER_VERSION,
564 + true
565 + );
566 +
567 + wp_register_style(
568 + 'jet-form-builder-others',
569 + Plugin::instance()->plugin_url( 'assets/build/frontend/main.css' ),
570 + array(),
571 + Plugin::instance()->get_version()
572 + );
573 +
574 + do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
575 + }
576 +
577 +}