-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldTypes.php
791 lines (672 loc) · 26.6 KB
/
FieldTypes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
<?php
namespace Locomotive\Cms\Modules\ACF;
use acf_field;
use Locomotive\Cms\Contracts\Bootable;
use WP_Post;
use function Locomotive\Cms\Support\with_filters;
use function Locomotive\Cms\Support\without_filters;
/**
* ACF Module: Field Types
*
* This module registers a collection of custom field types.
*/
class FieldTypes implements Bootable
{
public const DEFAULT_FC_ROW_POSITION = 10;
public const DEFAULT_FC_ROW_INCREMENT = 0.01;
/**
* Cache of oEmbed responses.
*
* @var array
*/
protected $oembed_response_cache = [];
/**
* Boots the module and registers actions and filters.
*
* @return void
*/
public function boot(): void
{
add_action('acf/init', [$this, 'disable_format_value_for_oembed'], 1);
add_filter('acf/pre_load_value/type=text', [$this, 'pre_load_value_for_wp_post_content'], 10, 3);
add_filter('acf/pre_load_value/type=textarea', [$this, 'pre_load_value_for_wp_post_content'], 10, 3);
add_filter('acf/pre_load_value/type=wysiwyg', [$this, 'pre_load_value_for_wp_post_content'], 10, 3);
add_filter('acf/pre_load_value/type=image', [$this, 'pre_load_value_for_wp_post_thumbnail'], 10, 3);
add_filter('acf/load_value/type=flexible_content', [$this, 'load_value_for_flexible_content'], 10, 3);
add_filter('acf/format_value/type=clone', [$this, 'format_value_for_sub_fields'], 20, 3);
add_filter('acf/format_value/type=flexible_content', [$this, 'format_value_for_sub_fields'], 20, 3);
add_filter('acf/format_value/type=group', [$this, 'format_value_for_sub_fields'], 20, 3);
add_filter('acf/format_value/type=repeater', [$this, 'format_value_for_sub_fields'], 20, 3);
add_filter('acf/format_value/type=number', 'acf_format_numerics', 20, 1);
add_filter('acf/format_value/type=ranger', 'acf_format_numerics', 20, 1);
// Trim whitespace before and after multi-line values.
add_filter('acf/format_value/type=textarea', 'trim', 20, 1);
add_filter('acf/format_value/type=wysiwyg', 'trim', 20, 1);
add_filter('acf/format_value/type=oembed', [$this, 'format_value_for_oembed'], 10, 3);
add_filter('acf/validate_value/type=text', [$this, 'validate_value_for_constraint_pattern'], 10, 3);
add_filter('acf/pre_update_value/type=text', [$this, 'pre_update_value_for_wp_post_content'], 10, 4);
add_filter('acf/pre_update_value/type=textarea', [$this, 'pre_update_value_for_wp_post_content'], 10, 4);
add_filter('acf/pre_update_value/type=wysiwyg', [$this, 'pre_update_value_for_wp_post_content'], 10, 4);
add_filter('acf/pre_update_value/type=image', [$this, 'pre_update_value_for_wp_post_thumbnail'], 10, 4);
add_filter('acf/update_value/type=flexible_content', [$this, 'update_value_for_flexible_content'], 10, 3);
add_filter('acf/update_value/type=oembed', [$this, 'update_value_for_oembed'], 10, 3);
if (is_admin()) {
add_action('acf/add_meta_boxes', [$this, 'filter_meta_boxes'], 10, 3);
add_filter('acf/get_field_group_style', [$this, 'filter_field_group_style'], 10, 1);
add_filter('acf/fields/wysiwyg/toolbars', [$this, 'register_wysiwyg_toolbars'], 10, 1);
add_action('acf/render_field/type=select', [$this, 'render_field_for_select']);
add_action('acf/render_field_settings/type=text', [$this, 'render_field_settings_for_wp_post_content']);
add_action('acf/render_field_settings/type=textarea', [$this, 'render_field_settings_for_wp_post_content']);
add_action('acf/render_field_settings/type=wysiwyg', [$this, 'render_field_settings_for_wp_post_content']);
add_action('acf/render_field_settings/type=image', [$this, 'render_field_settings_for_wp_post_thumbnail']);
add_action('acf/render_field_presentation_settings/type=flexible_content', [$this, 'render_field_settings_for_sorting_layouts']);
add_action('acf/render_field_validation_settings/type=select', [$this, 'render_field_settings_for_custom_values']);
add_action('acf/render_field_validation_settings/type=text', [$this, 'render_field_settings_for_constraint_pattern']);
}
}
/**
* Fires after metaboxes have been added.
*
* This function performs two routines:
* - Remove the post thumbnail meta box if the featured image field is present.
* - ~~Merge "hide_on_screen" values from all field groups instead of just the first field group.
* {@see \ACF_Form_Post::add_meta_boxes()}~~
*
* Note: I've disable the merging of "hide_on_screen" because {@see \ACF_Ajax_Check_Screen}
* can not be reliably handled.
*
* @listens action:acf/add_meta_boxes
*
* @param string $post_type The post type.
* @param WP_Post $post The post being edited.
* @param array $field_groups The field groups added.
* @return void
*/
public function filter_meta_boxes(string $post_type, WP_Post $post, array $field_groups): void
{
$thumbnail_support = (current_theme_supports('post-thumbnails', $post_type) && post_type_supports($post_type, 'thumbnail'));
// $hide_on_screen = [];
foreach ($field_groups as $field_group) {
/*
// Merge items to hide from the edit screen
if ( ! empty( $field_group['hide_on_screen'] ) && is_array( $field_group['hide_on_screen'] ) ) {
array_push( $hide_on_screen, ...$field_group['hide_on_screen'] );
}
*/
// Lookup post thumbnail proxy
if ($thumbnail_support) {
$fields = acf_get_fields($field_group);
foreach ($fields as $field) {
if ('image' === $field['type'] && !empty($field['save_post_thumbnail'])) {
remove_meta_box('postimagediv', $post_type, 'side');
return;
}
}
}
}
/*
$form_post = acf_get_instance( ACF_Form_Post::class );
if ( empty( $hide_on_screen ) && ! empty( $form_post->style ) ) {
$form_post->style = null;
} else {
$hide_on_screen = array_values( array_unique( $hide_on_screen ) );
$field_group = acf_validate_field_group( [
'hide_on_screen' => $hide_on_screen,
] );
$form_post->style = acf_get_field_group_style( $field_group );
}
*/
}
/**
* Sanitizes the CSS to ensure rules have a selector.
*
* @listens filter:acf/get_field_group_style
* Filters the generated CSS styles for field groups.
*
* @param string $style The CSS styles.
* @return string
*/
public function filter_field_group_style(string $style): string
{
if (' {display: none;}' === $style) {
return '';
}
return $style;
}
// Field Type: Flexible Content
// =========================================================================
/**
* Format the sub field values after it is loaded from the database.
*
* Removes array elements for Column, Tab, and Message field types,
* which mostly result in an empty key/value pair (`'' => null`).
*
* @listens filter:acf/format_value/type=clone
* @listens filter:acf/format_value/type=flexible_content
* @listens filter:acf/format_value/type=group
* @listens filter:acf/format_value/type=repeater
*
* @param mixed $value The value which was loaded from the database.
* @param int|string $post_id The post ID from which the value was loaded.
* @param array $field The field structure.
* @return mixed
*/
public function format_value_for_sub_fields($value, $post_id, $field)
{
if (is_array($value)) {
unset($value['']);
/** @todo PHP 8.1: Wrap loop in `array_is_list()` */
// Loop through layouts
foreach ($value as $i => $v) {
if (is_array($v)) {
unset($value[$i]['']);
}
}
}
return $value;
}
/**
* Modify the value of a Flexible Content field after it is loaded from the database.
*
* @listens filter:acf/load_value/type=flexible_content
*
* @param mixed $value The value of the field as found in the database.
* @param int|string $post_id The post ID which the value was loaded from.
* @param array $field The field structure.
* @return mixed The mutated $value.
*/
public function load_value_for_flexible_content($value, $post_id, array $field)
{
// Value will only be NULL on a new post
if ($value === null) {
$value = $this->add_initial_layouts_for_flexible_content($value, $field);
}
return $value;
}
/**
* Inject the initial layouts (e.g., required) and sort layout orders.
*
* @param array $value The value of the field as found in the database.
* @param array $field The field structure.
* @return mixed The mutated $value.
*/
protected function add_initial_layouts_for_flexible_content($value, array $field)
{
$value = acf_get_array($value);
$layouts = [];
foreach ($field['layouts'] as $k => $layout) {
if (!empty($layout['initial'])) {
$value[] = $layout['name'];
}
}
return $value;
}
/**
* Modify the value of a Flexible Content field before it is saved to the database.
*
* @listens filter:acf/update_value/type=flexible_content
*
* @param array $value The value of the field as found in the database.
* @param int|string $post_id The post ID which the value was loaded from.
* @param array $field The field structure.
* @return mixed The mutated $value.
*/
public function update_value_for_flexible_content($value, $post_id, array $field)
{
if (!empty($value)) {
$value = $this->sort_layouts_for_flexible_content($value, $field);
}
return $value;
}
/**
* Sort layouts of Flexible Content field.
*
* @param mixed $value The value of the field as found in the $_POST array.
* @param array $field The field structure.
* @return array
*/
protected function sort_layouts_for_flexible_content($value, array $field)
{
if (empty($field['sort'])) {
return $value;
}
// Sort layouts into names
$layouts = [];
foreach ($field['layouts'] as $k => $layout) {
$layouts[$layout['name']] = $layout;
}
$value = acf_get_array($value);
$position = static::DEFAULT_FC_ROW_POSITION;
foreach ($value as $i => $row) {
// Bail early if row is malformed
if (empty($row['acf_fc_layout'])) {
continue;
}
// Get layout name
$l = $row['acf_fc_layout'];
// Bail early if layout doesn't exist
if (empty($layouts[$l])) {
continue;
}
// Get layout
$layout = $layouts[$l];
// Default layout priority
if (!isset($layout['position'])) {
$layout['position'] = $position += static::DEFAULT_FC_ROW_INCREMENT;
}
// Set position on row for sorting
$value[$i]['_fc_position'] = $layout['position'];
}
uasort($value, function ($a, $b) {
$pA = $a['_fc_position'] ?? 0;
$pB = $b['_fc_position'] ?? 0;
if ($pA == $pB) {
return 0;
}
if ($pA < $pB) {
return -1;
}
return 1;
});
return $value;
}
/**
* Add a custom "sort" setting into Flexible Content field settings.
*
* @listens action:acf/render_field_presentation_settings/type=flexible_content
*
* @param acf_field|array $field ACF Field.
* @return void
*/
public function render_field_settings_for_sorting_layouts(array $field): void
{
// sort_layouts
acf_render_field_setting($field, [
'label' => __('Sort Layouts', 'acf'),
'instructions' => __('Automatically sort layouts by their internal layout order', 'acf'),
'name' => 'sort',
'type' => 'true_false',
'ui' => 1,
]);
}
// Field Type: Image
// =========================================================================
/**
* If the field is a "post_thumbnail" proxy, load that value.
*
* @listens filter:acf/pre_load_value/type=image
*
* @param mixed $value The value of the field as found in the database.
* @param int|string $post_id The post ID which the value was loaded from.
* @param array $field The field structure.
* @return mixed The mutated $value.
*/
public function pre_load_value_for_wp_post_thumbnail( $value, $post_id, array $field )
{
if ('image' === $field['type'] && !empty($field['save_post_thumbnail'])) {
return get_post_thumbnail_id($post_id);
}
return $value;
}
/**
* If the field is a "post_thumbnail" proxy, set the selected image as the post thumbnail
* then short-circuit the update_value logic.
*
* @listens filter:acf/pre_update_value/type=image
*
* @param ?bool $check The value to return instead of updating. Default NULL.
* @param mixed $value The value of the field as found in the $_POST array.
* @param int|string $post_id The post ID to save against.
* @param array $field The field structure.
* @return ?bool
*/
public function pre_update_value_for_wp_post_thumbnail($check, $value, $post_id, array $field)
{
if ('image' === $field['type'] && !empty($field['save_post_thumbnail'])) {
update_post_meta($post_id, '_thumbnail_id', $value);
return true;
}
return $check;
}
/**
* Add a custom "post_thumbnail" setting into Image field settings.
*
* @listens action:acf/render_field_settings/type=image
*
* @param acf_field|array $field ACF Field.
* @return void
*/
public function render_field_settings_for_wp_post_thumbnail(array $field) : void
{
// save_post_thumbnail
acf_render_field_setting($field, [
'label' => __('Save as Featured Image', 'acf'),
'instructions' => __('Associate the selected image as the post thumbnail', 'acf'),
'name' => 'save_post_thumbnail',
'type' => 'true_false',
'ui' => 1,
]);
}
// Field Type: oEmbed
// =========================================================================
/**
* Disable {@see \acf_field_oembed::format_value()} to replace
* ACF/WP formatting with custom formatting of oEmbed results.
*
* @listens action:acf/init
*
* @return void
*/
public function disable_format_value_for_oembed(): void
{
$field_type = acf_get_field_type('oembed');
remove_filter('acf/format_value/type=oembed', [$field_type, 'format_value']);
}
/**
* Format the $value after it is loaded from the database.
*
* @listens filter:acf/format_value/type=oembed
*
* @param mixed $value The value which was loaded from the database.
* @param int|string $post_id The post ID from which the value was loaded.
* @param array $field The field structure.
* @return string|null
*/
public function format_value_for_oembed($value, $post_id, $field)
{
if (!empty($value)) {
$value = $this->oembed_get_html($value, $post_id, $field);
}
return $value;
}
/**
* Ensures a detailed oEmbed object is saved.
*
* @listens filter:acf/update_value/type=oembed
* Filter the $value before it is saved to the database.
*
* @param mixed $value The value of the field as found in the $_POST array.
* @param int|string $post_id The post ID to save against.
* @param array $field The field structure.
* @return string|null
*/
public function update_value_for_oembed($value, $post_id, $field)
{
if (!empty($value)) {
$this->oembed_get_html($value, $post_id, $field);
}
return $value;
}
/**
* Attempts to fetch the embed HTML for a provided URL using oEmbed.
*
* Checks for a cached result (stored as custom post or in the post meta).
*
* @global \WP_Embed $wp_embed
*
* @see \WP_Embed::shortcode()
*
* @param mixed $value The URL to cache.
* @param int|string $post_id The post ID to save against.
* @param array $field The field structure.
* @return mixed The embed HTML on success, otherwise the original URL.
*/
public function oembed_get_html($value, $post_id, array $field)
{
if (empty($value)) {
return $value;
}
$attr = [
'width' => $field['width'],
'height' => $field['height'],
];
$func = function () use ($attr, $value) {
$func = function () use ($attr, $value) {
global $wp_embed;
return $wp_embed->shortcode($attr, $value);
};
return with_filters($func, [
['oembed_dataparse', [$this, 'oembed_dataparse'], 0, 3],
['oembed_result', [$this, 'oembed_result'], 0, 3],
]);
};
$html = without_filters($func, 'embed_oembed_html');
if ($html) {
return $html;
}
return $value;
}
/**
* Prepares to cache the oEmbed response.
*
* @listens WP#filter:oembed_dataparse
*
* @param string $html The returned oEmbed HTML.
* @param object $data A data object result from an oEmbed provider.
* @param string $url The URL of the content to be embedded.
* @return string
*/
public function oembed_dataparse($html, $data, $url)
{
if (is_object($data)) {
$this->oembed_response_cache[$url] = $data;
}
return $html;
}
/**
* Caches the oEmbed response.
*
* @listens WP#filter:oembed_result
*
* @param string $html The returned oEmbed HTML.
* @param string $url URL of the content to be embedded.
* @param array $args Optional arguments, usually passed from a shortcode.
* @return string
*/
public function oembed_result($html, $url, $args)
{
if (isset($this->oembed_response_cache[$url])) {
$data = $this->oembed_response_cache[$url];
$post = get_post();
if (!empty($post->ID)) {
unset($args['discover']);
$key_suffix = md5($url . serialize($args));
$cachekey_data = '_oembed_data_' . $key_suffix;
$data = json_decode(json_encode($data), true);
update_post_meta($post->ID, $cachekey_data, $data);
}
}
return $html;
}
// Field Type: Select
// =========================================================================
/**
* Inject custom "tags" setting into Select field.
*
* @listens action:acf/render_field/type=select
*
* @param acf_field|array $field ACF Field.
* @return void
*/
public function render_field_for_select($field): void
{
if (empty($field['tags'])) {
return;
}
$atts = [
'id' => $field['id'] . '-select2',
'data-tags' => $field['tags'],
'data-token-separators' => '[","]',
];
$html = '<script ' . acf_esc_atts($atts) . '></script>' . "\n";
echo $html;
}
/**
* Add a custom "tags" setting into Select field settings.
*
* @listens action:acf/render_field_validation_settings/type=select
*
* @param acf_field|array $field ACF Field.
* @return void
*/
public function render_field_settings_for_custom_values($field): void
{
// multiple
acf_render_field_setting($field, [
'label' => __('Create Values', 'acf'),
'instructions' => __('Allow new values to be created whilst editing', 'acf'),
'name' => 'tags',
'type' => 'true_false',
'ui' => 1,
]);
}
// Field Type: Text
// =========================================================================
/**
* If the field is a "post_content" or "post_excerpt" proxy, load that value.
*
* @listens filter:acf/pre_load_value/type=text
* @listens filter:acf/pre_load_value/type=textarea
* @listens filter:acf/pre_load_value/type=wysiwyg
*
* @param mixed $value The value of the field as found in the database.
* @param int|string $post_id The post ID which the value was loaded from.
* @param array $field The field structure.
* @return mixed The mutated $value.
*/
public function pre_load_value_for_wp_post_content($value, $post_id, array $field)
{
if (!empty( $field['save_post_content'])) {
return get_post_field('post_content', $post_id);
}
if (!empty( $field['save_post_excerpt'])) {
return get_post_field('post_excerpt', $post_id);
}
return $value;
}
/**
* If the field is a "post_content" or "post_excerpt" proxy, set the selected value
* as the post field then short-circuit the update_value logic.
*
* Sets the value as the post content or excerpt.
*
* @listens filter:acf/pre_update_value/type=text
* @listens filter:acf/pre_update_value/type=textarea
* @listens filter:acf/pre_update_value/type=wysiwyg
*
* @param ?bool $check The value to return instead of updating. Default NULL.
* @param mixed $value The value of the field as found in the $_POST array.
* @param int|string $post_id The post ID to save against.
* @param array $field The field structure.
* @return mixed
*/
public function pre_update_value_for_wp_post_content($check, $value, $post_id, array $field)
{
if (in_array($field['type'], ['text', 'textarea', 'wysiwyg'])) {
if (!empty($field['save_post_content'])) {
wp_update_post([
'ID' => $post_id,
'post_content' => $value,
]);
return true;
}
if (!empty($field['save_post_excerpt'])) {
wp_update_post([
'ID' => $post_id,
'post_excerpt' => wp_strip_all_tags($value),
]);
return true;
}
}
return $check;
}
/**
* Add a custom "post_content" or "post_excerpt" setting into text-based field settings.
*
* @listens action:acf/render_field_settings/type=text
* @listens action:acf/render_field_settings/type=textarea
* @listens action:acf/render_field_settings/type=wysiwyg
*
* @param acf_field|array $field ACF Field.
* @return void
*/
public function render_field_settings_for_wp_post_content(array $field) : void
{
// save_post_content
acf_render_field_setting($field, [
'label' => __('Save as Content', 'acf'),
'instructions' => __('Associate the text as the post content', 'acf'),
'name' => 'save_post_content',
'type' => 'true_false',
'ui' => 1,
]);
// save_post_excerpt
acf_render_field_setting($field, [
'label' => __('Save as Excerpt', 'acf'),
'instructions' => __('Associate the text as the post excerpt', 'acf'),
'name' => 'save_post_excerpt',
'type' => 'true_false',
'ui' => 1,
]);
}
/**
* Validates the $value before it is saved to the database.
*
* @listens filter:acf/validate_value/type=text
*
* @param bool $valid Whether or not the $value is valid.
* @param mixed $value The value to be saved.
* @param array $field The field structure.
* @param string $input The input name of the field.
* @return bool|string TRUE if the $value is valid, FALSE if invalid.
* Can also be returned as a custom error message.
*/
public function validate_value_for_constraint_pattern($valid, $value, array $field)
{
if (!empty($field['pattern'])) {
$pattern = '/^' . $field['pattern'] . '$/';
if (!preg_match($pattern, $value)) {
$valid = __('Value must match the requested format', 'acf');
}
}
return $valid;
}
/**
* Add a custom "pattern" setting into Text field settings.
*
* @listens action:acf/render_field_validation_settings/type=text
*
* @param acf_field|array $field ACF Field.
* @return void
*/
public function render_field_settings_for_constraint_pattern($field): void
{
// pattern
acf_render_field_setting($field, [
'label' => __('Pattern', 'acf'),
'instructions' => __('A regular expression that the value is checked against. The pattern must match the entire value.', 'acf'),
'name' => 'pattern',
'type' => 'text',
]);
}
// Field Type: WYSIWYG
// =========================================================================
/**
* Register additional custom toolbars for TinyMCE.
*
* @listens action:acf/fields/wysiwyg/toolbars
*
* @param array $field One or many TinyMCE toolbar configsets.
* @return array
*/
public function register_wysiwyg_toolbars(array $toolbars): array
{
$toolbars['Simple'] = [
1 => ['bold', 'italic', 'link', 'unlink', 'undo', 'redo'],
];
$toolbars['Notes'] = [
1 => ['bold', 'italic', 'bullist', 'numlist', 'link', 'unlink', 'undo', 'redo'],
];
return $toolbars;
}
}