PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.3.2
JetFormBuilder — Dynamic Blocks Form Builder v1.3.2
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 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / admin / editor.php
jetformbuilder / includes / admin Last commit date
pages 4 years ago tabs-handlers 4 years ago editor.php 4 years ago
editor.php
387 lines
1 <?php
2
3 namespace Jet_Form_Builder\Admin;
4
5 use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager;
6 use Jet_Form_Builder\Classes\Tools;
7 use Jet_Form_Builder\Gateways\Gateway_Manager;
8 use Jet_Form_Builder\Plugin;
9
10 /**
11 * Form editor class
12 * Thanks Tom J Nowell for initial editor idea and inspiration!
13 */
14
15 // If this file is called directly, abort.
16 if ( ! defined( 'WPINC' ) ) {
17 die;
18 }
19
20 /**
21 * Define Editor class
22 */
23 class Editor {
24
25 const EDITOR_HANDLE = 'jet-form-builder-editor';
26 const EDITOR_PACKAGE_HANDLE = 'jet-form-builder-editor-package';
27
28 /**
29 * Returns taxonomies list for the config
30 *
31 * @return [type] [description]
32 */
33 public function get_taxonomies_list() {
34
35 $taxonomies = get_taxonomies( array(), 'objects' );
36
37 $result = array();
38
39 foreach ( $taxonomies as $tax ) {
40 $result[] = array(
41 'value' => $tax->name,
42 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
43 );
44 }
45
46 return $result;
47
48 }
49
50 public function get_preset_config() {
51 return apply_filters(
52 'jet-form-builder/editor/preset-config',
53 array(
54 'global_fields' => array(
55 array(
56 'name' => 'from',
57 'label' => __( 'Source:', 'jet-form-builder' ),
58 'type' => 'select',
59 'options' => Tools::with_placeholder(
60 array(
61 array(
62 'value' => 'post',
63 'label' => __( 'Post', 'jet-form-builder' ),
64 ),
65 array(
66 'value' => 'user',
67 'label' => __( 'User', 'jet-form-builder' ),
68 ),
69 array(
70 'value' => 'query_var',
71 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
72 ),
73 )
74 ),
75 ),
76 array(
77 'name' => 'post_from',
78 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
79 'type' => 'select',
80 'options' => Tools::with_placeholder(
81 array(
82 array(
83 'value' => 'current_post',
84 'label' => __( 'Current post', 'jet-form-builder' ),
85 ),
86 array(
87 'value' => 'query_var',
88 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
89 ),
90 )
91 ),
92 'condition' => array(
93 'field' => 'from',
94 'value' => 'post',
95 ),
96 ),
97 array(
98 'name' => 'user_from',
99 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
100 'type' => 'select',
101 'options' => Tools::with_placeholder(
102 array(
103 array(
104 'value' => 'current_user',
105 'label' => __( 'Current user', 'jet-form-builder' ),
106 ),
107 array(
108 'value' => 'query_var',
109 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
110 ),
111 )
112 ),
113 'condition' => array(
114 'field' => 'from',
115 'value' => 'user',
116 ),
117 ),
118 array(
119 'name' => 'query_var',
120 'label' => __( 'Query variable name:', 'jet-form-builder' ),
121 'type' => 'text',
122 'custom_condition' => 'query_var',
123 'position' => 'dynamic',
124 ),
125 ),
126 'map_fields' => array(
127 array(
128 'name' => 'key',
129 'label' => __( 'Query variable key', 'jet-form-builder' ),
130 'type' => 'text',
131 'position' => 'general',
132 'parent_condition' => array(
133 'field' => 'from',
134 'value' => 'query_var',
135 ),
136 ),
137 array(
138 'name' => 'prop',
139 'label' => __( 'Post property', 'jet-form-builder' ),
140 'type' => 'select',
141 'options' => Tools::with_placeholder(
142 array(
143 array(
144 'value' => 'ID',
145 'label' => __( 'Post ID', 'jet-form-builder' ),
146 ),
147 array(
148 'value' => 'post_title',
149 'label' => __( 'Post Title', 'jet-form-builder' ),
150 ),
151 array(
152 'value' => 'post_content',
153 'label' => __( 'Post Content', 'jet-form-builder' ),
154 ),
155 array(
156 'value' => 'post_excerpt',
157 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
158 ),
159 array(
160 'value' => 'post_date',
161 'label' => __( 'Post Date', 'jet-form-builder' ),
162 ),
163 array(
164 'value' => 'post_date_gmt',
165 'label' => __( 'Post Date GMT', 'jet-form-builder' ),
166 ),
167 array(
168 'value' => 'post_thumb',
169 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
170 ),
171 array(
172 'value' => 'post_meta',
173 'label' => __( 'Post Meta', 'jet-form-builder' ),
174 ),
175 array(
176 'value' => 'post_terms',
177 'label' => __( 'Post Terms', 'jet-form-builder' ),
178 ),
179 )
180 ),
181 'parent_condition' => array(
182 'field' => 'from',
183 'value' => 'post',
184 ),
185 ),
186 array(
187 'name' => 'key',
188 'label' => __( 'Taxonomy', 'jet-form-builder' ),
189 'type' => 'select',
190 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
191 'parent_condition' => array(
192 'field' => 'from',
193 'value' => 'post',
194 ),
195 'condition' => array(
196 'field' => 'prop',
197 'value' => 'post_terms',
198 ),
199 ),
200 array(
201 'name' => 'key',
202 'label' => __( 'Meta field key', 'jet-form-builder' ),
203 'type' => 'text',
204 'parent_condition' => array(
205 'field' => 'from',
206 'value' => 'post',
207 ),
208 'condition' => array(
209 'field' => 'prop',
210 'value' => 'post_meta',
211 ),
212 ),
213 array(
214 'name' => 'prop',
215 'label' => __( 'User field', 'jet-form-builder' ),
216 'type' => 'select',
217 'options' => Tools::with_placeholder(
218 array(
219 array(
220 'value' => 'ID',
221 'label' => __( 'User ID', 'jet-form-builder' ),
222 ),
223 array(
224 'value' => 'user_login',
225 'label' => __( 'User Login', 'jet-form-builder' ),
226 ),
227 array(
228 'value' => 'user_email',
229 'label' => __( 'Email', 'jet-form-builder' ),
230 ),
231 array(
232 'value' => 'password',
233 'label' => __( 'Password', 'jet-form-builder' ),
234 ),
235 array(
236 'value' => 'first_name',
237 'label' => __( 'First Name', 'jet-form-builder' ),
238 ),
239 array(
240 'value' => 'last_name',
241 'label' => __( 'Last Name', 'jet-form-builder' ),
242 ),
243 array(
244 'value' => 'user_url',
245 'label' => __( 'User URL', 'jet-form-builder' ),
246 ),
247 array(
248 'value' => 'user_meta',
249 'label' => __( 'User Meta', 'jet-form-builder' ),
250 ),
251 )
252 ),
253 'parent_condition' => array(
254 'field' => 'from',
255 'value' => 'user',
256 ),
257 ),
258 array(
259 'name' => 'key',
260 'label' => __( 'Meta field key', 'jet-form-builder' ),
261 'type' => 'text',
262 'parent_condition' => array(
263 'field' => 'from',
264 'value' => 'user',
265 ),
266 'condition' => array(
267 'field' => 'prop',
268 'value' => 'user_meta',
269 ),
270 ),
271 ),
272 )
273 );
274 }
275
276 public function get_messages_default() {
277 return Plugin::instance()->post_type->get_messages_default();
278 }
279
280 /**
281 * Enqueue editor assets
282 *
283 * @return void
284 */
285 public function enqueue_assets() {
286 do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
287
288 wp_enqueue_script(
289 self::EDITOR_PACKAGE_HANDLE,
290 JET_FORM_BUILDER_URL . 'assets/js/package.js',
291 array(
292 'wp-editor',
293 'wp-core-data',
294 'wp-data',
295 'wp-block-library',
296 'wp-format-library',
297 'wp-api-fetch',
298 ),
299 JET_FORM_BUILDER_VERSION,
300 true
301 );
302
303 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
304
305 wp_enqueue_script(
306 self::EDITOR_HANDLE,
307 JET_FORM_BUILDER_URL . 'assets/js/editor.js',
308 array(),
309 JET_FORM_BUILDER_VERSION,
310 true
311 );
312
313 wp_enqueue_style(
314 self::EDITOR_HANDLE,
315 JET_FORM_BUILDER_URL . 'assets/css/editor.css',
316 array(
317 'media',
318 'l10n',
319 'buttons',
320 'wp-edit-blocks',
321 'wp-editor',
322 ),
323 JET_FORM_BUILDER_VERSION,
324 'all'
325 );
326
327 wp_localize_script(
328 self::EDITOR_PACKAGE_HANDLE,
329 'JetFormEditorData',
330 array(
331 'presetConfig' => $this->get_preset_config(),
332 'messagesDefault' => $this->get_messages_default(),
333 'gateways' => Gateway_Manager::instance()->editor_data(),
334 'helpForRepeaters' => $this->get_help_for_repeaters(),
335 'global_settings' => Tab_Handler_Manager::instance()->all(),
336 'jetEngineVersion' => Tools::get_jet_engine_version(),
337 )
338 );
339
340 do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
341 }
342
343 private function get_help_for_repeaters() {
344 return array(
345 'conditional_block' => array(
346 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
347 ),
348 'conditional_action' => array(
349 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
350 ),
351 );
352 }
353
354 public function enqueue_form_assets() {
355
356 $handle = 'jet-form-builder/form';
357
358 do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
359
360 wp_enqueue_script(
361 $handle,
362 JET_FORM_BUILDER_URL . 'assets/js/form-block.js',
363 array(
364 'wp-editor',
365 'wp-core-data',
366 'wp-data',
367 'wp-block-library',
368 'wp-format-library',
369 'wp-api-fetch',
370 ),
371 JET_FORM_BUILDER_VERSION,
372 true
373 );
374
375 wp_enqueue_style(
376 'jet-form-builder-others',
377 Plugin::instance()->plugin_url( 'assets/css/frontend.css' ),
378 array(),
379 Plugin::instance()->get_version()
380 );
381
382 do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
383
384 }
385
386 }
387