PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8
Advanced Custom Fields: Extended v0.8
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / fields / field-flexible-content.php
acf-extended / includes / fields Last commit date
field-advanced-link.php 6 years ago field-button.php 6 years ago field-clone.php 6 years ago field-column.php 6 years ago field-dynamic-message.php 6 years ago field-file.php 6 years ago field-flexible-content.php 6 years ago field-forms.php 6 years ago field-group.php 6 years ago field-hidden.php 6 years ago field-image.php 6 years ago field-post-statuses.php 6 years ago field-post-types.php 6 years ago field-recaptcha.php 6 years ago field-repeater.php 6 years ago field-select.php 6 years ago field-slug.php 6 years ago field-taxonomies.php 6 years ago field-taxonomy-terms.php 6 years ago field-textarea.php 6 years ago field-user-roles.php 6 years ago
field-flexible-content.php
1014 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 /**
7 * Add Settings
8 */
9 add_action('acf/render_field_settings/type=flexible_content', 'acfe_flexible_settings', 0);
10 function acfe_flexible_settings($field){
11
12 // Stylised button
13 acf_render_field_setting($field, array(
14 'label' => __('Stylised Button'),
15 'name' => 'acfe_flexible_stylised_button',
16 'key' => 'acfe_flexible_stylised_button',
17 'instructions' => __('Better layouts button integration'),
18 'type' => 'true_false',
19 'message' => '',
20 'default_value' => false,
21 'ui' => true,
22 'ui_on_text' => '',
23 'ui_off_text' => '',
24 ));
25
26 // Hide Empty Message
27 acf_render_field_setting($field, array(
28 'label' => __('Hide Empty Message'),
29 'name' => 'acfe_flexible_hide_empty_message',
30 'key' => 'acfe_flexible_hide_empty_message',
31 'instructions' => __('Hide the empty message box'),
32 'type' => 'true_false',
33 'message' => '',
34 'default_value' => false,
35 'ui' => true,
36 'ui_on_text' => '',
37 'ui_off_text' => '',
38 'conditional_logic' => array(
39 array(
40 array(
41 'field' => 'acfe_flexible_stylised_button',
42 'operator' => '!=',
43 'value' => '1',
44 ),
45 )
46 )
47 ));
48
49 // Empty Message
50 acf_render_field_setting($field, array(
51 'label' => __('Empty Message'),
52 'name' => 'acfe_flexible_empty_message',
53 'key' => 'acfe_flexible_empty_message',
54 'instructions' => __('Text displayed when the flexible field is empty'),
55 'type' => 'text',
56 'placeholder' => __('Click the "Add Row" button below to start creating your layout'),
57 'conditional_logic' => array(
58 array(
59 array(
60 'field' => 'acfe_flexible_stylised_button',
61 'operator' => '!=',
62 'value' => '1',
63 ),
64 array(
65 'field' => 'acfe_flexible_hide_empty_message',
66 'operator' => '!=',
67 'value' => '1',
68 )
69 )
70 )
71 ));
72
73 // Layouts thumbnails
74 acf_render_field_setting($field, array(
75 'label' => __('Layouts: Thumbnails'),
76 'name' => 'acfe_flexible_layouts_thumbnails',
77 'key' => 'acfe_flexible_layouts_thumbnails',
78 'instructions' => __('Set a thumbnail for each layouts. You must save the field group to apply this setting'),
79 'type' => 'true_false',
80 'message' => '',
81 'default_value' => false,
82 'ui' => true,
83 'ui_on_text' => '',
84 'ui_off_text' => '',
85 ));
86
87 // Layouts: Render
88 acf_render_field_setting($field, array(
89 'label' => __('Layouts: Render'),
90 'name' => 'acfe_flexible_layouts_templates',
91 'key' => 'acfe_flexible_layouts_templates',
92 'instructions' => __('Set template, style & javascript files for each layouts. This setting is mandatory in order to use <code style="font-size:11px;">get_flexible()</code> function. You must save the field group to apply this setting'),
93 'type' => 'true_false',
94 'message' => '',
95 'default_value' => false,
96 'ui' => true,
97 'ui_on_text' => '',
98 'ui_off_text' => '',
99 ));
100
101 // Layouts: Preview
102 acf_render_field_setting($field, array(
103 'label' => __('Layouts: Dynamic Preview'),
104 'name' => 'acfe_flexible_layouts_previews',
105 'key' => 'acfe_flexible_layouts_previews',
106 'instructions' => __('Use layouts render settings to display a dynamic preview in the post administration'),
107 'type' => 'true_false',
108 'message' => '',
109 'default_value' => false,
110 'ui' => true,
111 'ui_on_text' => '',
112 'ui_off_text' => '',
113 'conditional_logic' => array(
114 array(
115 array(
116 'field' => 'acfe_flexible_layouts_templates',
117 'operator' => '==',
118 'value' => '1',
119 )
120 )
121 )
122 ));
123
124 // Layouts: Placholder
125 acf_render_field_setting($field, array(
126 'label' => __('Layouts: Placeholder'),
127 'name' => 'acfe_flexible_layouts_placeholder',
128 'key' => 'acfe_flexible_layouts_placeholder',
129 'instructions' => __('Display a placeholder with a pencil icon, making edition easier'),
130 'type' => 'true_false',
131 'message' => '',
132 'default_value' => false,
133 'ui' => true,
134 'ui_on_text' => '',
135 'ui_off_text' => '',
136 'conditional_logic' => array(
137 array(
138 array(
139 'field' => 'acfe_flexible_layouts_previews',
140 'operator' => '==',
141 'value' => '',
142 )
143 )
144 )
145 ));
146
147 // Layouts: Close Button
148 acf_render_field_setting($field, array(
149 'label' => __('Layouts: Close Button'),
150 'name' => 'acfe_flexible_close_button',
151 'key' => 'acfe_flexible_close_button',
152 'instructions' => __('Display a close button to collapse the layout'),
153 'type' => 'true_false',
154 'message' => '',
155 'default_value' => false,
156 'ui' => true,
157 'ui_on_text' => '',
158 'ui_off_text' => '',
159 ));
160
161 // Layouts: Title Edition
162 acf_render_field_setting($field, array(
163 'label' => __('Layouts: Title Edition'),
164 'name' => 'acfe_flexible_title_edition',
165 'key' => 'acfe_flexible_title_edition',
166 'instructions' => __('Allow layout title edition'),
167 'type' => 'true_false',
168 'message' => '',
169 'default_value' => false,
170 'ui' => true,
171 'ui_on_text' => '',
172 'ui_off_text' => '',
173 ));
174
175 // Layouts: Copy/Paste
176 acf_render_field_setting($field, array(
177 'label' => __('Layouts: Copy/Paste'),
178 'name' => 'acfe_flexible_copy_paste',
179 'key' => 'acfe_flexible_copy_paste',
180 'instructions' => __('Allow copy/paste layouts functions'),
181 'type' => 'true_false',
182 'message' => '',
183 'default_value' => false,
184 'ui' => true,
185 'ui_on_text' => '',
186 'ui_off_text' => '',
187 ));
188
189 // Modal: Edition
190 acf_render_field_setting($field, array(
191 'label' => __('Layouts Modal: Edition'),
192 'name' => 'acfe_flexible_modal_edition',
193 'key' => 'acfe_flexible_modal_edition',
194 'instructions' => __('Edit layout content in a modal'),
195 'type' => 'true_false',
196 'message' => '',
197 'default_value' => false,
198 'ui' => true,
199 'ui_on_text' => '',
200 'ui_off_text' => '',
201 ));
202
203 // Modal: Selection
204 acf_render_field_setting($field, array(
205 'label' => __('Layouts Modal: Selection'),
206 'name' => 'acfe_flexible_modal',
207 'key' => 'acfe_flexible_modal',
208 'instructions' => __('Select layouts in a modal'),
209 'type' => 'group',
210 'layout' => 'block',
211 'sub_fields' => array(
212 array(
213 'label' => '',
214 'name' => 'acfe_flexible_modal_enabled',
215 'key' => 'acfe_flexible_modal_enabled',
216 'type' => 'true_false',
217 'instructions' => '',
218 'required' => false,
219 'wrapper' => array(
220 'width' => '',
221 'class' => '',
222 'id' => '',
223 ),
224 'message' => '',
225 'default_value' => false,
226 'ui' => true,
227 'ui_on_text' => '',
228 'ui_off_text' => '',
229 'conditional_logic' => false,
230 ),
231 array(
232 'label' => '',
233 'name' => 'acfe_flexible_modal_title',
234 'key' => 'acfe_flexible_modal_title',
235 'type' => 'text',
236 'prepend' => __('Modal Title'),
237 'placeholder' => 'Add Row',
238 'instructions' => false,
239 'required' => false,
240 'wrapper' => array(
241 'width' => '35',
242 'class' => '',
243 'id' => '',
244 ),
245 'conditional_logic' => array(
246 array(
247 array(
248 'field' => 'acfe_flexible_modal_enabled',
249 'operator' => '==',
250 'value' => '1',
251 )
252 )
253 )
254 ),
255 array(
256 'label' => '',
257 'name' => 'acfe_flexible_modal_col',
258 'key' => 'acfe_flexible_modal_col',
259 'type' => 'select',
260 'prepend' => '',
261 'instructions' => false,
262 'required' => false,
263 'choices' => array(
264 '1' => '1 column',
265 '2' => '2 columns',
266 '3' => '3 columns',
267 '4' => '4 columns',
268 '5' => '5 columns',
269 '6' => '6 columns',
270 ),
271 'default_value' => '4',
272 'wrapper' => array(
273 'width' => '15',
274 'class' => '',
275 'id' => '',
276 ),
277 'conditional_logic' => array(
278 array(
279 array(
280 'field' => 'acfe_flexible_modal_enabled',
281 'operator' => '==',
282 'value' => '1',
283 )
284 )
285 )
286 ),
287 array(
288 'label' => '',
289 'name' => 'acfe_flexible_modal_categories',
290 'key' => 'acfe_flexible_modal_categories',
291 'type' => 'true_false',
292 'message' => __('Categories'),
293 'instructions' => false,
294 'required' => false,
295 'wrapper' => array(
296 'width' => '25',
297 'class' => '',
298 'id' => '',
299 ),
300 'conditional_logic' => array(
301 array(
302 array(
303 'field' => 'acfe_flexible_modal_enabled',
304 'operator' => '==',
305 'value' => '1',
306 )
307 )
308 )
309 ),
310 )
311 ));
312
313 // Layouts: Force State
314 acf_render_field_setting($field, array(
315 'label' => __('Layouts: Force State'),
316 'name' => 'acfe_flexible_layouts_state',
317 'key' => 'acfe_flexible_layouts_state',
318 'instructions' => __('Force layouts to be collapsed or opened'),
319 'type' => 'select',
320 'allow_null' => true,
321 'choices' => array(
322 'collapse' => 'Collapsed',
323 'open' => 'Opened',
324 ),
325 'conditional_logic' => array(
326 array(
327 array(
328 'field' => 'acfe_flexible_modal_edition',
329 'operator' => '!=',
330 'value' => '1',
331 )
332 )
333 )
334 ));
335
336 // Layouts: Remove Collapse
337 acf_render_field_setting($field, array(
338 'label' => __('Layouts: Remove Collapse'),
339 'name' => 'acfe_flexible_layouts_remove_collapse',
340 'key' => 'acfe_flexible_layouts_remove_collapse',
341 'instructions' => __('Remove collapse action'),
342 'type' => 'true_false',
343 'message' => '',
344 'default_value' => false,
345 'ui' => true,
346 'ui_on_text' => '',
347 'ui_off_text' => '',
348 'conditional_logic' => array(
349 array(
350 array(
351 'field' => 'acfe_flexible_modal_edition',
352 'operator' => '!=',
353 'value' => '1',
354 ),
355 array(
356 'field' => 'acfe_flexible_layouts_state',
357 'operator' => '==',
358 'value' => 'open',
359 )
360 )
361 )
362 ));
363
364 }
365
366 add_action('acf/render_field', 'acfe_flexible_layouts_settings_before', 0);
367 function acfe_flexible_layouts_settings_before($field){
368
369 if($field['_name'] != 'label' || stripos($field['name'], '[layouts]') === false)
370 return;
371
372 echo '</li>';
373
374 acf_render_field_wrap(array(
375 'label' => __('Settings'),
376 'type' => 'hidden',
377 'name' => 'acfe_flexible_settings_label'
378 ), 'ul');
379
380 echo '<li>';
381
382 }
383
384 add_action('acf/render_field', 'acfe_flexible_layouts_settings', 10);
385 function acfe_flexible_layouts_settings($field){
386
387 if($field['_name'] != 'max' || stripos($field['name'], '[layouts]') === false)
388 return;
389
390 $layout_prefix = $field['prefix'];
391
392 parse_str($layout_prefix, $output);
393 $keys = acfe_array_keys_r($output);
394
395 $_field_id = $keys[1];
396 $_layout_key = $keys[3];
397
398 $field_flexible = acf_get_field($_field_id);
399 $layout = $field_flexible['layouts'][$_layout_key];
400
401 $is_flexible_layouts_thumbnails = isset($field_flexible['acfe_flexible_layouts_thumbnails']) && !empty($field_flexible['acfe_flexible_layouts_thumbnails']);
402 $is_flexible_layouts_templates = isset($field_flexible['acfe_flexible_layouts_templates']) && !empty($field_flexible['acfe_flexible_layouts_templates']);
403 $is_flexible_modal_enabled = isset($field_flexible['acfe_flexible_modal']['acfe_flexible_modal_enabled']) && !empty($field_flexible['acfe_flexible_modal']['acfe_flexible_modal_enabled']);
404 $is_flexible_modal_categories = isset($field_flexible['acfe_flexible_modal']['acfe_flexible_modal_categories']) && !empty($field_flexible['acfe_flexible_modal']['acfe_flexible_modal_categories']);
405
406 // Category
407 if($is_flexible_modal_enabled && $is_flexible_modal_categories){
408
409 $acfe_flexible_category = isset($layout['acfe_flexible_category']) ? $layout['acfe_flexible_category'] : '';
410
411 acf_render_field_wrap(array(
412 'prepend' => __('Category'),
413 'name' => 'acfe_flexible_category',
414 'type' => 'text',
415 'class' => 'acf-fc-meta-name',
416 'prefix' => $layout_prefix,
417 'value' => $acfe_flexible_category,
418 'placeholder' => __('Multiple categories can be set using "|"')
419
420 /*
421 'conditional_logic' => array(
422 array(
423 array(
424 'field' => 'acfe_flexible_modal_enabled',
425 'operator' => '==',
426 'value' => '1',
427 ),
428 array(
429 'field' => 'acfe_flexible_modal_categories',
430 'operator' => '==',
431 'value' => '1',
432 )
433 )
434 )
435 */
436
437 ), 'ul');
438
439 }
440
441 // Template
442 if($is_flexible_layouts_templates){
443
444 $acfe_flexible_render_template = isset($layout['acfe_flexible_render_template']) ? $layout['acfe_flexible_render_template'] : '';
445
446 acf_render_field_wrap(array(
447 'label' => __('Render'),
448 'prepend' => str_replace(home_url(), '', ACFE_THEME_URL) . '/',
449 'name' => 'acfe_flexible_render_template',
450 'type' => 'text',
451 'class' => 'acf-fc-meta-name',
452 'prefix' => $layout_prefix,
453 'value' => $acfe_flexible_render_template,
454 'placeholder' => 'template.php',
455
456 /*
457 'conditional_logic' => array(
458 array(
459 array(
460 'field' => 'acfe_flexible_layouts_templates',
461 'operator' => '==',
462 'value' => '1',
463 )
464 )
465 )
466 */
467
468 ), 'ul');
469
470 $acfe_flexible_render_style = isset($layout['acfe_flexible_render_style']) ? $layout['acfe_flexible_render_style'] : '';
471
472 acf_render_field_wrap(array(
473 'prepend' => str_replace(home_url(), '', ACFE_THEME_URL) . '/',
474 'name' => 'acfe_flexible_render_style',
475 'type' => 'text',
476 'class' => 'acf-fc-meta-name',
477 'prefix' => $layout_prefix,
478 'value' => $acfe_flexible_render_style,
479 'placeholder' => 'style.css',
480
481 /*
482 'conditional_logic' => array(
483 array(
484 array(
485 'field' => 'acfe_flexible_layouts_templates',
486 'operator' => '==',
487 'value' => '1',
488 )
489 )
490 )
491 */
492
493 ), 'ul');
494
495 $acfe_flexible_render_script = isset($layout['acfe_flexible_render_script']) ? $layout['acfe_flexible_render_script'] : '';
496
497 acf_render_field_wrap(array(
498 'prepend' => str_replace(home_url(), '', ACFE_THEME_URL) . '/',
499 'name' => 'acfe_flexible_render_script',
500 'type' => 'text',
501 'class' => 'acf-fc-meta-name',
502 'prefix' => $layout_prefix,
503 'value' => $acfe_flexible_render_script,
504 'placeholder' => 'script.js',
505
506 /*
507 'conditional_logic' => array(
508 array(
509 array(
510 'field' => 'acfe_flexible_layouts_templates',
511 'operator' => '==',
512 'value' => '1',
513 )
514 )
515 )
516 */
517
518 ), 'ul');
519
520 }
521
522 // Thumbnail
523 if($is_flexible_layouts_thumbnails){
524
525 $acfe_flexible_thumbnail = isset($layout['acfe_flexible_thumbnail']) ? $layout['acfe_flexible_thumbnail'] : '';
526
527 acf_render_field_wrap(array(
528 'label' => __('Thumbnail'),
529 'name' => 'acfe_flexible_thumbnail',
530 'type' => 'image',
531 'class' => '',
532 'prefix' => $layout_prefix,
533 'value' => $acfe_flexible_thumbnail,
534 'return_format' => 'array',
535 'preview_size' => 'thumbnail',
536 'library' => 'all',
537
538 /*
539 'conditional_logic' => array(
540 array(
541 array(
542 'field' => 'acfe_flexible_layouts_thumbnails',
543 'operator' => '==',
544 'value' => '1',
545 )
546 )
547 )
548 */
549
550 ), 'ul');
551
552 }
553
554 }
555
556 add_filter('acf/field_wrapper_attributes', 'acfe_flexible_wrapper', 10, 2);
557 function acfe_flexible_wrapper($wrapper, $field){
558
559 if($field['type'] !== 'flexible_content')
560 return $wrapper;
561
562 // Stylised button
563 if(acf_maybe_get($field, 'acfe_flexible_stylised_button')){
564
565 $wrapper['data-acfe-flexible-stylised-button'] = 1;
566
567 }
568
569 // Hide Empty Message
570 if(acf_maybe_get($field, 'acfe_flexible_hide_empty_message') || acf_maybe_get($field, 'acfe_flexible_stylised_button')){
571
572 $wrapper['data-acfe-flexible-hide-empty-message'] = 1;
573
574 }
575
576 // Modal: Edition
577 if(acf_maybe_get($field, 'acfe_flexible_modal_edition')){
578
579 $wrapper['data-acfe-flexible-modal-edition'] = 1;
580
581 }
582
583 // Modal: Selection
584 if(isset($field['acfe_flexible_modal']['acfe_flexible_modal_enabled']) && !empty($field['acfe_flexible_modal']['acfe_flexible_modal_enabled'])){
585
586 $wrapper['data-acfe-flexible-modal'] = 1;
587
588 // Columns
589 if(isset($field['acfe_flexible_modal']['acfe_flexible_modal_col']) && !empty($field['acfe_flexible_modal']['acfe_flexible_modal_col']))
590 $wrapper['data-acfe-flexible-modal-col'] = $field['acfe_flexible_modal']['acfe_flexible_modal_col'];
591
592 // Title
593 if(isset($field['acfe_flexible_modal']['acfe_flexible_modal_title']) && !empty($field['acfe_flexible_modal']['acfe_flexible_modal_title']))
594 $wrapper['data-acfe-flexible-modal-title'] = $field['acfe_flexible_modal']['acfe_flexible_modal_title'];
595
596 }
597
598 // Layouts: Title Edition
599 if(acf_maybe_get($field, 'acfe_flexible_title_edition')){
600
601 $wrapper['data-acfe-flexible-title-edition'] = 1;
602
603 }
604
605 // Layouts: Close Button
606 if(acf_maybe_get($field, 'acfe_flexible_close_button')){
607
608 $wrapper['data-acfe-flexible-close-button'] = 1;
609
610 }
611
612 // Layouts: Copy/paste
613 if(acf_maybe_get($field, 'acfe_flexible_copy_paste')){
614
615 $wrapper['data-acfe-flexible-copy-paste'] = 1;
616
617 }
618
619 // Layouts: State
620 if(!acf_maybe_get($field, 'acfe_flexible_modal_edition')){
621
622 if(acf_maybe_get($field, 'acfe_flexible_layouts_state')){
623
624 // Collapse
625 if($field['acfe_flexible_layouts_state'] === 'collapse'){
626
627 $wrapper['data-acfe-flexible-close'] = 1;
628
629 }
630
631 // Open
632 elseif($field['acfe_flexible_layouts_state'] === 'open'){
633
634 $wrapper['data-acfe-flexible-open'] = 1;
635
636 }
637
638 }
639
640 // Layouts Remove Collapse
641 if(acf_maybe_get($field, 'acfe_flexible_layouts_remove_collapse')){
642
643 $wrapper['data-acfe-flexible-remove-collapse'] = 1;
644
645 }
646
647 }
648
649 // Layouts Placeholder
650 if(acf_maybe_get($field, 'acfe_flexible_layouts_placeholder')){
651
652 $wrapper['data-acfe-flexible-placeholder'] = 1;
653
654 }
655
656 // Layouts Previews
657 if(acf_maybe_get($field, 'acfe_flexible_layouts_templates') && acf_maybe_get($field, 'acfe_flexible_layouts_previews')){
658
659 $wrapper['data-acfe-flexible-preview'] = 1;
660
661 }
662
663 // Placeholder Icon
664 $layout_placeholder_icon = false;
665 $layout_placeholder_icon = apply_filters('acfe/flexible/placeholder/icon', $layout_placeholder_icon, $field);
666 $layout_placeholder_icon = apply_filters('acfe/flexible/placeholder/icon/name=' . $field['_name'], $layout_placeholder_icon, $field);
667 $layout_placeholder_icon = apply_filters('acfe/flexible/placeholder/icon/key=' . $field['key'], $layout_placeholder_icon, $field);
668
669 if(!empty($layout_placeholder_icon)){
670
671 $wrapper['data-acfe-flexible-placeholder-icon'] = $layout_placeholder_icon;
672
673 }
674
675 // Lock sortable
676 $acfe_flexible_lock_sortable = false;
677 $acfe_flexible_lock_sortable = apply_filters('acfe/flexible/lock', $acfe_flexible_lock_sortable, $field);
678 $acfe_flexible_lock_sortable = apply_filters('acfe/flexible/lock/name=' . $field['_name'], $acfe_flexible_lock_sortable, $field);
679 $acfe_flexible_lock_sortable = apply_filters('acfe/flexible/lock/key=' . $field['key'], $acfe_flexible_lock_sortable, $field);
680
681 if($acfe_flexible_lock_sortable){
682
683 $wrapper['data-acfe-flexible-lock'] = 1;
684
685 }
686
687 // Remove actions
688 $acfe_flexible_remove_actions = false;
689 $acfe_flexible_remove_actions = apply_filters('acfe/flexible/remove_actions', $acfe_flexible_remove_actions, $field);
690 $acfe_flexible_remove_actions = apply_filters('acfe/flexible/remove_actions/name=' . $field['_name'], $acfe_flexible_remove_actions, $field);
691 $acfe_flexible_remove_actions = apply_filters('acfe/flexible/remove_actions/key=' . $field['key'], $acfe_flexible_remove_actions, $field);
692
693 if($acfe_flexible_remove_actions){
694
695 $wrapper['data-acfe-flexible-remove-actions'] = 1;
696
697 }
698
699 return $wrapper;
700
701 }
702
703 add_filter('acf/fields/flexible_content/no_value_message', 'acfe_flexible_empty_message', 10, 2);
704 function acfe_flexible_empty_message($message, $field){
705
706 if(!isset($field['acfe_flexible_empty_message']) || empty($field['acfe_flexible_empty_message']))
707 return $message;
708
709 return $field['acfe_flexible_empty_message'];
710
711 }
712
713 add_filter('acf/prepare_field/type=flexible_content', 'acfe_flexible_layout_title_prepare');
714 function acfe_flexible_layout_title_prepare($field){
715
716 if(empty($field['layouts']))
717 return $field;
718
719 foreach($field['layouts'] as $k => &$layout){
720
721 // vars
722 $thumbnail = false;
723 $span_class = false;
724
725 // thumbnail
726 if(isset($field['acfe_flexible_layouts_thumbnails']) && !empty($field['acfe_flexible_layouts_thumbnails'])){
727
728 $class = $style = array();
729 $class[] = 'acfe-flexible-layout-thumbnail';
730
731 // Modal disabled
732 if(!isset($field['acfe_flexible_modal']['acfe_flexible_modal_enabled']) || empty($field['acfe_flexible_modal']['acfe_flexible_modal_enabled']))
733 $class[] = 'acfe-flexible-layout-thumbnail-no-modal';
734
735 // Thumbnail is set
736 $thumbnail_found = false;
737
738 $acfe_flexible_thumbnail = false;
739 if(isset($layout['acfe_flexible_thumbnail']) && !empty($layout['acfe_flexible_thumbnail']))
740 $acfe_flexible_thumbnail = $layout['acfe_flexible_thumbnail'];
741
742 // Filter: acfe/flexible/layout/thumbnail/name={field:flexible:name}&layout={field:flexible:layout_name}
743 // Flexible Thumbnails
744 $acfe_flexible_thumbnail = apply_filters('acfe/flexible/thumbnail/name=' . $field['_name'], $acfe_flexible_thumbnail, $field, $layout);
745 $acfe_flexible_thumbnail = apply_filters('acfe/flexible/thumbnail/key=' . $field['key'], $acfe_flexible_thumbnail, $field, $layout);
746
747 $acfe_flexible_thumbnail = apply_filters('acfe/flexible/layout/thumbnail/layout=' . $layout['name'], $acfe_flexible_thumbnail, $field, $layout);
748 $acfe_flexible_thumbnail = apply_filters('acfe/flexible/layout/thumbnail/name=' . $field['_name'] . '&layout=' . $layout['name'], $acfe_flexible_thumbnail, $field, $layout);
749 $acfe_flexible_thumbnail = apply_filters('acfe/flexible/layout/thumbnail/key=' . $field['key'] . '&layout=' . $layout['name'], $acfe_flexible_thumbnail, $field, $layout);
750
751 if(!empty($acfe_flexible_thumbnail)){
752
753 // Thumbnail ID
754 if(is_numeric($acfe_flexible_thumbnail)){
755
756 if($thumbnail_src = wp_get_attachment_url($acfe_flexible_thumbnail)){
757
758 $thumbnail_found = true;
759 $style[] = 'background-image:url(' . $thumbnail_src . ');';
760
761 }
762
763 }
764
765 // Thumbnail URL
766 else{
767
768 $thumbnail_found = true;
769 $style[] = 'background-image:url(' . $acfe_flexible_thumbnail . ');';
770
771 }
772
773 }
774
775 // Thumbnail not found
776 if(!$thumbnail_found){
777
778 $class[] = 'acfe-flexible-layout-thumbnail-not-found';
779
780 }
781
782 $thumbnail = '<div class="' . implode(' ', $class) . '" style="' . implode(' ', $style) . '"></div>';
783
784 }
785
786 // No Thumbnails
787 else{
788
789 $span_class = 'class="no-thumbnail"';
790
791 }
792
793 // Category
794 $category = '';
795 if(isset($layout['acfe_flexible_category']) && !empty($layout['acfe_flexible_category'])){
796
797 $category = 'data-acfe-flexible-category="' . $layout['acfe_flexible_category'] . '"';
798
799 }
800
801 $layout['label'] = $thumbnail . '<span '.$category.' ' . $span_class . '>' . $layout['label'] . '</span>';
802
803 }
804
805 return $field;
806
807 }
808
809 add_filter('acf/fields/flexible_content/layout_title', 'acfe_flexible_layout_title_ajax', 0, 4);
810 function acfe_flexible_layout_title_ajax($title, $field, $layout, $i){
811
812 // Remove thumbnail
813 $title = preg_replace('#<div class="acfe-flexible-layout-thumbnail(.*?)</div>#', '', $title);
814
815 // Title Edition
816 if(isset($field['acfe_flexible_title_edition']) && !empty($field['acfe_flexible_title_edition'])){
817
818 // Get Layout Title
819 $acfe_flexible_layout_title = get_sub_field('acfe_flexible_layout_title');
820 if(!empty($acfe_flexible_layout_title))
821 $title = wp_unslash($acfe_flexible_layout_title);
822
823 // Return
824 return '<span class="acfe-layout-title acf-js-tooltip" title="' . __('Layout', 'acfe') . ': ' . esc_attr(strip_tags($layout['label'])) . '"><span class="acfe-layout-title-text">' . $title . '</span></span>';
825
826 }
827
828 // Return
829 return '<span class="acfe-layout-title-text">' . $title . '</span></span>';
830
831 }
832
833 add_action('acf/render_field/type=flexible_content', 'acfe_flexible_render_field');
834 function acfe_flexible_render_field($field){
835
836 if(!isset($field['acfe_flexible_layouts_templates']) || empty($field['acfe_flexible_layouts_templates']) || !isset($field['acfe_flexible_layouts_previews']) || empty($field['acfe_flexible_layouts_previews']) || empty($field['layouts']))
837 return;
838
839 // Vars
840 $is_preview = true;
841
842 // Actions
843 do_action('acfe/flexible/enqueue', $field, $is_preview);
844 do_action('acfe/flexible/enqueue/name=' . $field['_name'], $field, $is_preview);
845 do_action('acfe/flexible/enqueue/key=' . $field['key'], $field, $is_preview);
846
847 // Layouts Previews
848 foreach($field['layouts'] as $layout_key => $layout){
849
850 // Render: Enqueue
851 acfe_flexible_render_layout_enqueue($layout, $field);
852
853 }
854
855 }
856
857 add_action('wp_ajax_acfe/flexible/layout_preview', 'acfe_flexible_layout_preview');
858 function acfe_flexible_layout_preview(){
859
860 // Options
861 $options = acf_parse_args($_POST, array(
862 'post_id' => 0,
863 'i' => 0,
864 'field_key' => '',
865 'nonce' => '',
866 'layout' => '',
867 'value' => array()
868 ));
869
870 // Load field
871 $field = acf_get_field($options['field_key']);
872 if(!$field)
873 die;
874
875 // Get Flexible
876 $flexible = acf_get_field_type('flexible_content');
877
878 // Vars
879 $layout = $flexible->get_layout($options['layout'], $field);
880 if(!$layout)
881 die;
882
883 if(!acf_maybe_get($layout, 'acfe_flexible_thumbnail'))
884 $layout['acfe_flexible_thumbnail'] = false;
885
886 // Flexible Thumbnails
887 $layout['acfe_flexible_thumbnail'] = apply_filters('acfe/flexible/thumbnail/name=' . $field['_name'], $layout['acfe_flexible_thumbnail'], $field, $layout);
888 $layout['acfe_flexible_thumbnail'] = apply_filters('acfe/flexible/thumbnail/key=' . $field['key'], $layout['acfe_flexible_thumbnail'], $field, $layout);
889
890 // Layout Thumbnails
891 $layout['acfe_flexible_thumbnail'] = apply_filters('acfe/flexible/layout/thumbnail/layout=' . $layout['name'], $layout['acfe_flexible_thumbnail'], $field, $layout);
892 $layout['acfe_flexible_thumbnail'] = apply_filters('acfe/flexible/layout/thumbnail/name=' . $field['_name'] . '&layout=' . $layout['name'], $layout['acfe_flexible_thumbnail'], $field, $layout);
893 $layout['acfe_flexible_thumbnail'] = apply_filters('acfe/flexible/layout/thumbnail/key=' . $field['key'] . '&layout=' . $layout['name'], $layout['acfe_flexible_thumbnail'], $field, $layout);
894
895 $get_field_object = get_field_object($options['field_key'], $options['post_id'], false, false);
896
897 $preview_key = 'preview_' . $options['field_key'];
898 $get_field_object['key'] = $preview_key;
899
900 acf_add_local_field($get_field_object);
901
902 add_filter('acf/load_value/key=' . $preview_key, function($value, $post_id, $field) use($options){
903
904 $value = array();
905 $value[0] = wp_unslash($options['value']);
906
907 return $value;
908
909 }, 10, 3);
910
911 if(have_rows($preview_key)):
912 while(have_rows($preview_key)): the_row();
913
914 // Flexible Preview
915 do_action('acfe/flexible/preview/name=' . $field['_name'], $field, $layout);
916 do_action('acfe/flexible/preview/key=' . $field['key'], $field, $layout);
917
918 // Flexible Layout Preview
919 do_action('acfe/flexible/layout/preview/layout=' . $layout['name'], $field, $layout);
920 do_action('acfe/flexible/layout/preview/name=' . $field['_name'] . '&layout=' . $layout['name'], $field, $layout);
921 do_action('acfe/flexible/layout/preview/key=' . $field['key'] . '&layout=' . $layout['name'], $field, $layout);
922
923 // ACFE: All Flexible Preview
924 do_action('acfe/flexible/preview', $field, $layout);
925
926 endwhile;
927 endif;
928
929 die;
930
931 }
932
933 add_action('acfe/flexible/preview', 'acfe_flexible_layout_preview_render', 99, 2);
934 function acfe_flexible_layout_preview_render($field, $layout){
935
936 global $is_preview;
937
938 $is_preview = true;
939
940 acfe_flexible_render_layout_template($layout, $field);
941
942 }
943
944 add_filter('acfe/flexible/render/template', 'acfe_flexible_layout_render_template_setting', 0, 4);
945 function acfe_flexible_layout_render_template_setting($return, $field, $layout, $is_preview){
946
947 if(isset($layout['acfe_flexible_render_template']) && !empty($layout['acfe_flexible_render_template']))
948 $return = $layout['acfe_flexible_render_template'];
949
950 return $return;
951
952 }
953
954 add_filter('acfe/flexible/render/style', 'acfe_flexible_layout_render_style_setting', 0, 4);
955 function acfe_flexible_layout_render_style_setting($return, $field, $layout, $is_preview){
956
957 if(isset($layout['acfe_flexible_render_style']) && !empty($layout['acfe_flexible_render_style']))
958 $return = $layout['acfe_flexible_render_style'];
959
960 return $return;
961
962 }
963
964 add_filter('acfe/flexible/render/script', 'acfe_flexible_layout_render_script_setting', 0, 4);
965 function acfe_flexible_layout_render_script_setting($return, $field, $layout, $is_preview){
966
967 if(isset($layout['acfe_flexible_render_script']) && !empty($layout['acfe_flexible_render_script']))
968 $return = $layout['acfe_flexible_render_script'];
969
970 return $return;
971
972 }
973
974 add_filter('acf/load_field/type=flexible_content', 'acfe_flexible_layout_title_subfield');
975 function acfe_flexible_layout_title_subfield($field){
976
977 global $typenow;
978
979 if(acf_is_screen(array('edit-acf-field-group', 'acf-field-group')) || (isset($typenow) && $typenow === 'acf-field-group'))
980 return $field;
981
982 if(!isset($field['layouts']) || empty($field['layouts']))
983 return $field;
984
985 if(!isset($field['acfe_flexible_title_edition']) || empty($field['acfe_flexible_title_edition']))
986 return $field;
987
988 foreach($field['layouts'] as $layout_key => &$layout){
989
990 // Add the input as the first sub_field
991 array_unshift($layout['sub_fields'] , array(
992 'ID' => false,
993 'label' => false,
994 'key' => 'field_acfe_flexible_layout_title',
995 'name' => 'acfe_flexible_layout_title',
996 '_name' => 'acfe_flexible_layout_title',
997 'type' => 'text',
998 'required' => 0,
999 'maxlength' => null,
1000 'parent' => false,
1001 'default_value' => $layout['label'],
1002 'placeholder' => $layout['label'],
1003 'wrapper' => array(
1004 'id' => '',
1005 'class' => '',
1006 'width' => '',
1007 )
1008 ));
1009
1010 }
1011
1012 return $field;
1013
1014 }