-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.php
More file actions
1322 lines (1271 loc) · 71.1 KB
/
example.php
File metadata and controls
1322 lines (1271 loc) · 71.1 KB
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WP_Field v2.3 — Примеры использования всех типов полей
*
* Подключение: require_once 'path/to/example.php';
*
* Добавляет страницу в меню "Инструменты" с демонстрацией всех 48 типов полей
*/
if (! defined('ABSPATH')) {
exit;
}
// Подключаем WP_Field если еще не подключен
if (! class_exists('WP_Field')) {
require_once __DIR__.'/WP_Field.php';
}
class WP_Field_Examples
{
public function __construct()
{
add_action('admin_menu', [$this, 'add_menu_page']);
add_action('admin_init', [$this, 'save_settings']);
add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']);
// Подключаем CodeMirror для code_editor
add_action('admin_enqueue_scripts', function ($hook): void {
if ($hook === 'tools_page_wp-field-examples') {
wp_enqueue_code_editor(['type' => 'text/css']);
}
});
}
/**
* Подключение необходимых скриптов и стилей
*/
public function enqueue_assets($hook): void
{
// Загружаем только на нашей странице
if ($hook !== 'tools_page_wp-field-examples') {
return;
}
// WP встроенные скрипты
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('jquery-ui-sortable');
// wp-color-picker для color полей (с зависимостью iris)
wp_enqueue_script('iris');
wp_enqueue_script('wp-color-picker');
wp_enqueue_style('wp-color-picker');
// wp-media для media полей
wp_enqueue_media();
// Наш JS для зависимостей и инициализации
$wp_field_url = plugin_dir_url(__FILE__);
$wp_field_ver = defined('WP_DEBUG') && WP_DEBUG ? time() : '2.3.0';
wp_enqueue_script(
'wp-field-main',
$wp_field_url.'assets/js/wp-field.js',
['jquery', 'wp-color-picker', 'jquery-ui-sortable'],
$wp_field_ver,
true,
);
// Добавляем inline скрипт для гарантированной инициализации Color Picker
wp_add_inline_script('wp-field-main', '
jQuery(document).ready(function($) {
// Дополнительная инициализация Color Picker после загрузки страницы
setTimeout(function() {
if (typeof $.fn.wpColorPicker !== "undefined") {
$(".wp-color-picker-field").each(function() {
if (!$(this).hasClass("wp-color-picker")) {
$(this).wpColorPicker();
}
});
}
}, 500);
});
');
// Наш CSS
wp_enqueue_style(
'wp-field-main',
$wp_field_url.'assets/css/wp-field.css',
['wp-color-picker'],
$wp_field_ver,
);
// Prism.js для подсветки синтаксиса
wp_enqueue_style(
'prism-css',
'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css',
[],
'1.29.0',
);
// Используем полную версию Prism с поддержкой PHP
wp_enqueue_script(
'prism-js',
'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js',
[],
'1.29.0',
true,
);
// Добавляем поддержку PHP через data-атрибут
wp_add_inline_script('prism-js', '
if (typeof Prism !== "undefined") {
Prism.languages.php = Prism.languages.extend("clike", {
keyword: /\\b(?:and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|private|protected|parent|throw|null|echo|print|trait|namespace|final|yield|goto|instanceof|finally|try|catch)\\b/i,
constant: /\\b[A-Z0-9_]{2,}\\b/,
comment: {
pattern: /(^|[^\\\\])(?:\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*)/,
lookbehind: true
}
});
}
', 'after');
}
/**
* Добавить страницу в меню Инструменты
*/
public function add_menu_page(): void
{
add_management_page(
'WP_Field Examples',
'WP_Field Examples',
'manage_options',
'wp-field-examples',
[$this, 'render_page'],
);
}
/**
* Сохранение настроек
*/
public function save_settings(): void
{
if (! isset($_POST['wp_field_examples_nonce'])) {
return;
}
if (! wp_verify_nonce($_POST['wp_field_examples_nonce'], 'wp_field_examples_save')) {
return;
}
if (! current_user_can('manage_options')) {
return;
}
// Сохраняем все поля
$fields = $this->get_all_fields();
foreach ($fields as $section) {
foreach ($section['fields'] as $field) {
if (isset($_POST[$field['id']])) {
update_option('wpf_example_'.$field['id'], $_POST[$field['id']]);
}
}
}
add_settings_error('wp_field_examples', 'settings_updated', 'Настройки сохранены!', 'updated');
}
/**
* Рендер страницы
*/
public function render_page(): void
{
?>
<div class="wrap">
<h1>WP_Field v3.0 — Примеры всех типов полей</h1>
<div class="notice notice-info">
<p><strong>48 типов полей</strong> с системой зависимостей, поддержкой всех типов хранилищ и встроенными WP компонентами.</p>
<p>📌 <strong>Новое:</strong> <a href="<?php echo admin_url('tools.php?page=wp-field-v3-demo'); ?>">Смотрите v3.0 Demo</a> с Fluent API, Repeater и Flexible Content!</p>
</div>
<?php settings_errors('wp_field_examples'); ?>
<form method="post" action="">
<?php wp_nonce_field('wp_field_examples_save', 'wp_field_examples_nonce'); ?>
<div class="wp-field-examples-container">
<?php $this->render_all_fields(); ?>
</div>
<p class="submit">
<button type="submit" class="button button-primary button-large">Сохранить все настройки</button>
<button type="button" class="button button-secondary" onclick="location.reload()">Сбросить</button>
</p>
</form>
</div>
<style>
.wp-field-examples-container {
background: #fff;
padding: 20px;
margin: 20px 0;
border: 1px solid #ccd0d4;
box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.wp-field-section {
margin-bottom: 40px;
padding-bottom: 30px;
border-bottom: 2px solid #f0f0f0;
}
.wp-field-section:last-child {
border-bottom: none;
}
.wp-field-section h2 {
margin-top: 0;
padding: 10px 15px;
background: #f9f9f9;
border-left: 4px solid #0073aa;
}
.wp-field-section .description {
padding: 0 15px;
color: #666;
font-style: italic;
}
.wp-field-example {
margin: 20px 0;
padding: 15px;
background: #fafafa;
border-left: 3px solid #0073aa;
}
.wp-field-example h3 {
margin-top: 0;
color: #0073aa;
}
.wp-field-example h3 code {
background: #e8f4f8;
padding: 2px 8px;
border-radius: 3px;
font-size: 12px;
color: #0073aa;
font-weight: normal;
}
.wp-field-example details {
margin-top: 15px;
}
.wp-field-example details summary {
cursor: pointer;
color: #0073aa;
font-weight: 600;
padding: 8px 12px;
background: #f0f8ff;
border-radius: 4px;
user-select: none;
transition: background 0.2s;
}
.wp-field-example details summary:hover {
background: #e0f0ff;
}
.wp-field-example details[open] summary {
margin-bottom: 10px;
}
.wp-field-example pre {
margin: 0;
border-radius: 4px;
overflow: hidden;
}
.wp-field-example pre code {
display: block;
padding: 15px !important;
margin: 0;
font-size: 13px;
line-height: 1.6;
overflow-x: auto;
background: #2d2d2d !important;
}
.wp-field-description {
background: #f0f8ff;
padding: 12px 15px;
border-left: 3px solid #0073aa;
margin: 10px 0;
border-radius: 3px;
}
.wp-field-description p {
margin: 0;
color: #333;
}
.wp-field-preview {
background: #fff;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 4px;
margin: 15px 0;
}
.wp-field-arguments,
.wp-field-code,
.wp-field-advanced {
margin: 15px 0;
}
.wp-field-arguments summary,
.wp-field-code summary,
.wp-field-advanced summary {
cursor: pointer;
color: #0073aa;
font-weight: 600;
padding: 10px 15px;
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: 4px;
user-select: none;
transition: background 0.2s;
}
.wp-field-arguments summary:hover,
.wp-field-code summary:hover,
.wp-field-advanced summary:hover {
background: #f0f0f0;
}
.wp-field-arguments[open] summary,
.wp-field-code[open] summary,
.wp-field-advanced[open] summary {
margin-bottom: 15px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.wp-field-args-table {
width: 100%;
border-collapse: collapse;
background: #fff;
border: 1px solid #ddd;
border-top: none;
}
.wp-field-args-table th,
.wp-field-args-table td {
padding: 10px 12px;
text-align: left;
border-bottom: 1px solid #e0e0e0;
}
.wp-field-args-table th {
background: #f5f5f5;
font-weight: 600;
color: #333;
}
.wp-field-args-table tr:last-child td {
border-bottom: none;
}
.wp-field-args-table code {
background: #f0f0f0;
padding: 2px 6px;
border-radius: 3px;
font-size: 12px;
color: #d63384;
}
.wp-field-advanced-item {
background: #fff;
padding: 15px;
border: 1px solid #ddd;
border-top: none;
margin-bottom: 15px;
}
.wp-field-advanced-item:first-child {
border-top: 1px solid #ddd;
}
.wp-field-advanced-item:last-child {
margin-bottom: 0;
}
.wp-field-advanced-item h4 {
margin: 0 0 8px 0;
color: #0073aa;
font-size: 14px;
}
.wp-field-advanced-item p {
margin: 0 0 10px 0;
color: #666;
font-size: 13px;
}
.wp-field-advanced-item pre {
margin: 0;
}
</style>
<?php
}
/**
* Рендер всех полей по категориям
*/
private function render_all_fields(): void
{
$sections = $this->get_all_fields();
foreach ($sections as $section) {
echo '<div class="wp-field-section">';
echo '<h2>'.esc_html($section['title']).'</h2>';
if (! empty($section['description'])) {
echo '<p class="description">'.esc_html($section['description']).'</p>';
}
foreach ($section['fields'] as $field) {
$this->render_field_example($field);
}
echo '</div>';
}
}
/**
* Рендер примера одного поля
*/
private function render_field_example($field): void
{
echo '<div class="wp-field-example">';
echo '<h3>'.esc_html($field['label']).' <code>'.esc_html($field['type']).'</code></h3>';
// Описание поля
if (! empty($field['example_desc'])) {
echo '<div class="wp-field-description">';
echo '<p>'.wp_kses_post($field['example_desc']).'</p>';
echo '</div>';
}
// Рендерим поле
echo '<div class="wp-field-preview">';
WP_Field::make($field, true, 'options');
echo '</div>';
// Список аргументов
if (! empty($field['arguments'])) {
echo '<details class="wp-field-arguments"><summary>📋 Список аргументов</summary>';
echo '<table class="wp-field-args-table">';
echo '<thead><tr><th>Аргумент</th><th>Тип</th><th>По умолчанию</th><th>Описание</th></tr></thead>';
echo '<tbody>';
foreach ($field['arguments'] as $arg) {
printf(
'<tr><td><code>%s</code></td><td><code>%s</code></td><td><code>%s</code></td><td>%s</td></tr>',
esc_html($arg['name']),
esc_html($arg['type']),
esc_html($arg['default'] ?? '—'),
esc_html($arg['desc']),
);
}
echo '</tbody></table>';
echo '</details>';
}
// Базовый пример кода
if (! empty($field['example_code'])) {
echo '<details class="wp-field-code"><summary>💻 Базовый пример</summary>';
echo '<pre><code class="language-php">'.esc_html($field['example_code']).'</code></pre>';
echo '</details>';
}
// Расширенные примеры
if (! empty($field['advanced_examples'])) {
echo '<details class="wp-field-advanced"><summary>🚀 Расширенные примеры</summary>';
foreach ($field['advanced_examples'] as $example) {
echo '<div class="wp-field-advanced-item">';
if (! empty($example['title'])) {
echo '<h4>'.esc_html($example['title']).'</h4>';
}
if (! empty($example['desc'])) {
echo '<p>'.esc_html($example['desc']).'</p>';
}
echo '<pre><code class="language-php">'.esc_html($example['code']).'</code></pre>';
echo '</div>';
}
echo '</details>';
}
echo '</div>';
}
/**
* Общие аргументы для всех полей
*/
private function get_common_arguments()
{
return [
['name' => 'id', 'type' => 'string', 'default' => '—', 'desc' => 'Уникальный идентификатор (обязательно)'],
['name' => 'type', 'type' => 'string', 'default' => 'text', 'desc' => 'Тип поля'],
['name' => 'label', 'type' => 'string', 'default' => '', 'desc' => 'Заголовок поля'],
['name' => 'desc', 'type' => 'string', 'default' => '', 'desc' => 'Описание под полем'],
['name' => 'default', 'type' => 'mixed', 'default' => '', 'desc' => 'Значение по умолчанию'],
['name' => 'class', 'type' => 'string', 'default' => '', 'desc' => 'CSS класс'],
['name' => 'dependency', 'type' => 'array', 'default' => '[]', 'desc' => 'Условия зависимости'],
['name' => 'attributes', 'type' => 'array', 'default' => '[]', 'desc' => 'HTML атрибуты'],
];
}
/**
* Получить расширенные данные для типа поля
* Примечание: все данные теперь встроены в example.php
*/
private function get_field_data($type)
{
// field-data.php удалён, все примеры встроены в example.php
return ['arguments' => [], 'advanced_examples' => []];
}
/**
* Объединить общие и специфичные аргументы
*/
private function merge_arguments($type, $specific_args = [])
{
$common = $this->get_common_arguments();
return array_merge($common, $specific_args);
}
/**
* Получить все поля для демонстрации
*/
private function get_all_fields()
{
return [
// Базовые поля
[
'title' => '1. Базовые поля (9)',
'description' => 'Стандартные HTML5 input типы',
'fields' => [
[
'id' => 'text_field',
'type' => 'text',
'label' => 'Text — Текстовое поле',
'placeholder' => 'Введите текст...',
'desc' => 'Стандартное текстовое поле',
'example_desc' => 'Базовое текстовое поле для ввода любого текста. Поддерживает placeholder, валидацию, зависимости и все стандартные HTML5 атрибуты.',
'arguments' => [
['name' => 'id', 'type' => 'string', 'default' => '—', 'desc' => 'Уникальный идентификатор поля (обязательно)'],
['name' => 'type', 'type' => 'string', 'default' => 'text', 'desc' => 'Тип поля'],
['name' => 'label', 'type' => 'string', 'default' => '', 'desc' => 'Заголовок поля'],
['name' => 'placeholder', 'type' => 'string', 'default' => '', 'desc' => 'Текст-подсказка'],
['name' => 'desc', 'type' => 'string', 'default' => '', 'desc' => 'Описание под полем'],
['name' => 'default', 'type' => 'string', 'default' => '', 'desc' => 'Значение по умолчанию'],
['name' => 'class', 'type' => 'string', 'default' => '', 'desc' => 'CSS класс для поля'],
['name' => 'dependency', 'type' => 'array', 'default' => '[]', 'desc' => 'Условия зависимости'],
['name' => 'attributes', 'type' => 'array', 'default' => '[]', 'desc' => 'HTML атрибуты'],
],
'example_code' => "WP_Field::make([\n 'id' => 'text_field',\n 'type' => 'text',\n 'label' => 'Текст',\n 'placeholder' => 'Введите текст...'\n]);",
'advanced_examples' => [
[
'title' => 'С валидацией и классом',
'desc' => 'Добавление CSS класса и HTML атрибутов для валидации',
'code' => "WP_Field::make([\n 'id' => 'username',\n 'type' => 'text',\n 'label' => 'Имя пользователя',\n 'placeholder' => 'Только латиница и цифры',\n 'class' => 'regular-text',\n 'attributes' => [\n 'pattern' => '[a-zA-Z0-9]+',\n 'required' => true,\n 'minlength' => 3,\n 'maxlength' => 20\n ],\n 'desc' => 'От 3 до 20 символов'\n]);",
],
[
'title' => 'С зависимостью от другого поля',
'desc' => 'Поле отображается только если включен чекбокс',
'code' => "WP_Field::make([\n 'id' => 'custom_text',\n 'type' => 'text',\n 'label' => 'Пользовательский текст',\n 'dependency' => [\n ['enable_custom', '==', '1']\n ]\n]);",
],
[
'title' => 'Для post meta',
'desc' => 'Сохранение в метаполе записи',
'code' => "// В metabox callback:\n\$post_id = get_the_ID();\n\nWP_Field::make([\n 'id' => 'custom_title',\n 'type' => 'text',\n 'label' => 'Дополнительный заголовок'\n], true, 'post', \$post_id);\n\n// Получение значения:\n\$value = get_post_meta(\$post_id, 'custom_title', true);",
],
],
],
[
'id' => 'password_field',
'type' => 'password',
'label' => 'Password — Пароль',
'placeholder' => '••••••••',
'desc' => 'Поле для ввода пароля (скрытый текст)',
'example_code' => "WP_Field::make(['type' => 'password']);",
],
[
'id' => 'email_field',
'type' => 'email',
'label' => 'Email — Email адрес',
'placeholder' => 'user@example.com',
'desc' => 'Поле с валидацией email',
'example_code' => "WP_Field::make(['type' => 'email']);",
],
[
'id' => 'url_field',
'type' => 'url',
'label' => 'URL — Ссылка',
'placeholder' => 'https://example.com',
'desc' => 'Поле с валидацией URL',
'example_code' => "WP_Field::make(['type' => 'url']);",
],
[
'id' => 'tel_field',
'type' => 'tel',
'label' => 'Tel — Телефон',
'placeholder' => '+7 (999) 123-45-67',
'desc' => 'Поле для ввода телефона',
'example_code' => "WP_Field::make(['type' => 'tel']);",
],
[
'id' => 'number_field',
'type' => 'number',
'label' => 'Number — Число',
'min' => 0,
'max' => 100,
'step' => 1,
'desc' => 'Числовое поле с min/max/step',
'example_code' => "WP_Field::make([\n 'type' => 'number',\n 'min' => 0,\n 'max' => 100,\n 'step' => 1\n]);",
],
[
'id' => 'range_field',
'type' => 'range',
'label' => 'Range — Диапазон',
'min' => 0,
'max' => 100,
'step' => 5,
'desc' => 'Ползунок для выбора значения',
'example_code' => "WP_Field::make(['type' => 'range']);",
],
array_merge([
'id' => 'textarea_field',
'type' => 'textarea',
'label' => 'Textarea — Многострочный текст',
'rows' => 5,
'placeholder' => 'Введите многострочный текст...',
'desc' => 'Текстовая область для длинного текста',
'example_desc' => 'Многострочное текстовое поле для ввода длинного текста. Поддерживает настройку количества строк и placeholder.',
'example_code' => "WP_Field::make([\n 'type' => 'textarea',\n 'rows' => 5\n]);",
], $this->get_field_data('textarea')),
],
],
// Выборные поля
[
'title' => '2. Выборные поля (5)',
'description' => 'Поля для выбора из списка опций',
'fields' => [
array_merge([
'id' => 'select_field',
'type' => 'select',
'label' => 'Select — Выпадающий список',
'options' => [
'option1' => 'Опция 1',
'option2' => 'Опция 2',
'option3' => 'Опция 3',
],
'desc' => 'Выбор одного значения из списка',
'example_desc' => 'Выпадающий список для выбора одного значения. Поддерживает группировку опций, динамическую загрузку и placeholder.',
'example_code' => "WP_Field::make([\n 'type' => 'select',\n 'options' => [\n 'key1' => 'Label 1',\n 'key2' => 'Label 2'\n ]\n]);",
], $this->get_field_data('select')),
[
'id' => 'multiselect_field',
'type' => 'multiselect',
'label' => 'Multiselect — Множественный выбор',
'options' => [
'red' => 'Красный',
'green' => 'Зелёный',
'blue' => 'Синий',
],
'desc' => 'Выбор нескольких значений (Ctrl+Click)',
'example_code' => "WP_Field::make([\n 'type' => 'multiselect',\n 'options' => [...]\n]);",
],
[
'id' => 'radio_field',
'type' => 'radio',
'label' => 'Radio — Радиокнопки',
'options' => [
'yes' => 'Да',
'no' => 'Нет',
'maybe' => 'Возможно',
],
'desc' => 'Выбор одного значения из группы',
'example_code' => "WP_Field::make(['type' => 'radio']);",
],
[
'id' => 'checkbox_field',
'type' => 'checkbox',
'label' => 'Checkbox — Одиночный чекбокс',
'desc' => 'Включить/выключить опцию',
'example_code' => "WP_Field::make(['type' => 'checkbox']);",
],
[
'id' => 'checkbox_group_field',
'type' => 'checkbox_group',
'label' => 'Checkbox Group — Группа чекбоксов',
'options' => [
'feature1' => 'Функция 1',
'feature2' => 'Функция 2',
'feature3' => 'Функция 3',
],
'desc' => 'Выбор нескольких значений',
'example_code' => "WP_Field::make([\n 'type' => 'checkbox_group',\n 'options' => [...]\n]);",
],
],
],
// Продвинутые поля
[
'title' => '3. Продвинутые поля (9)',
'description' => 'Поля с использованием встроенных WP компонентов',
'fields' => [
[
'id' => 'editor_field',
'type' => 'editor',
'label' => 'Editor — WordPress редактор',
'desc' => 'Встроенный WordPress TinyMCE редактор',
'example_desc' => 'Полнофункциональный WYSIWYG редактор',
'example_code' => "WP_Field::make(['type' => 'editor']);",
],
array_merge([
'id' => 'media_field',
'type' => 'media',
'label' => 'Media — Медиафайл',
'desc' => 'Выбор файла из медиабиблиотеки с URL и превью',
'example_desc' => 'Выбор любого файла из медиабиблиотеки WordPress. Поддерживает preview, url поле, placeholder и фильтр по типу файлов (image, video, audio).',
'example_code' => "WP_Field::make([
'type' => 'media',
'preview' => true, // показать превью
'url' => true, // показать URL поле
'placeholder' => 'Не выбрано',
'library' => 'image' // фильтр: image, video, audio
]);",
], $this->get_field_data('media')),
[
'id' => 'media_no_preview',
'type' => 'media',
'label' => 'Media без превью',
'preview' => false,
'desc' => 'Только URL без превью',
'example_code' => "WP_Field::make(['type' => 'media', 'preview' => false]);",
],
[
'id' => 'media_no_url',
'type' => 'media',
'label' => 'Media без URL',
'url' => false,
'desc' => 'Только кнопка загрузки',
'example_code' => "WP_Field::make(['type' => 'media', 'url' => false]);",
],
[
'id' => 'media_image_only',
'type' => 'media',
'label' => 'Media только изображения',
'library' => 'image',
'desc' => 'Фильтр по типу: только изображения',
'example_code' => "WP_Field::make(['type' => 'media', 'library' => 'image']);",
],
[
'id' => 'media_video_only',
'type' => 'media',
'label' => 'Media только видео',
'library' => 'video',
'desc' => 'Фильтр по типу: только видео',
'example_code' => "WP_Field::make(['type' => 'media', 'library' => 'video']);",
],
[
'id' => 'media_audio_only',
'type' => 'media',
'label' => 'Media только аудио',
'library' => 'audio',
'desc' => 'Фильтр по типу: только аудио',
'example_code' => "WP_Field::make(['type' => 'media', 'library' => 'audio']);",
],
[
'id' => 'image_field',
'type' => 'image',
'label' => 'Image — Изображение',
'desc' => 'Выбор изображения с превью',
'example_desc' => 'Показывает превью выбранного изображения с кнопкой удаления',
'example_code' => "WP_Field::make(['type' => 'image']);",
],
[
'id' => 'image_no_preview',
'type' => 'image',
'label' => 'Image без превью',
'preview' => false,
'desc' => 'Только URL без превью',
'example_code' => "WP_Field::make(['type' => 'image', 'preview' => false]);",
],
[
'id' => 'image_placeholder',
'type' => 'image',
'label' => 'Image с placeholder',
'placeholder' => 'http://',
'desc' => 'Кастомный placeholder для URL поля',
'example_code' => "WP_Field::make(['type' => 'image', 'placeholder' => 'http://']);",
],
[
'id' => 'file_field',
'type' => 'file',
'label' => 'File — Файл',
'desc' => 'Выбор любого файла',
'example_code' => "WP_Field::make(['type' => 'file']);",
],
[
'id' => 'file_image_only',
'type' => 'file',
'label' => 'File только изображения',
'library' => 'image',
'button_text' => 'Upload Image',
'desc' => 'Фильтр по типу: только изображения',
'example_code' => "WP_Field::make(['type' => 'file', 'library' => 'image']);",
],
[
'id' => 'file_video_only',
'type' => 'file',
'label' => 'File только видео',
'library' => 'video',
'button_text' => 'Upload Video',
'desc' => 'Фильтр по типу: только видео',
'example_code' => "WP_Field::make(['type' => 'file', 'library' => 'video']);",
],
[
'id' => 'file_audio_only',
'type' => 'file',
'label' => 'File только аудио',
'library' => 'audio',
'button_text' => 'Upload Audio',
'desc' => 'Фильтр по типу: только аудио',
'example_code' => "WP_Field::make(['type' => 'file', 'library' => 'audio']);",
],
array_merge([
'id' => 'gallery_field',
'type' => 'gallery',
'label' => 'Gallery — Галерея',
'desc' => 'Выбор нескольких изображений с превью в виде плиток',
'example_desc' => 'Множественный выбор изображений с возможностью сортировки перетаскиванием. Отображает превью всех выбранных изображений с возможностью редактирования и удаления.',
'example_code' => "WP_Field::make(['type' => 'gallery']);",
], $this->get_field_data('gallery')),
[
'id' => 'gallery_custom_buttons',
'type' => 'gallery',
'label' => 'Gallery с кастомными кнопками',
'add_button' => 'Add Image(s)',
'edit_button' => 'Edit Images',
'clear_button' => 'Remove Images',
'desc' => 'Кастомные тексты для кнопок управления',
'example_code' => "WP_Field::make([
'type' => 'gallery',
'add_button' => 'Add Image(s)',
'edit_button' => 'Edit Images',
'clear_button' => 'Remove Images'
]);",
],
array_merge([
'id' => 'color_field',
'type' => 'color',
'label' => 'Color — Выбор цвета с прозрачностью',
'default' => '#0073aa',
'alpha' => true,
'desc' => 'WordPress Color Picker с поддержкой альфа-канала (прозрачность)',
'example_desc' => 'Встроенный WordPress color picker с поддержкой прозрачности (RGBA). Позволяет выбирать цвет визуально или вводить HEX/RGBA значение.',
'example_code' => "WP_Field::make([\n 'type' => 'color',\n 'alpha' => true, // включить прозрачность\n 'default' => 'rgba(0, 115, 170, 0.5)'\n]);\n\n// Без прозрачности:\nWP_Field::make([\n 'type' => 'color',\n 'alpha' => false\n]);",
], $this->get_field_data('color')),
[
'id' => 'date_field',
'type' => 'date',
'label' => 'Date — Дата',
'desc' => 'Выбор даты (HTML5)',
'example_code' => "WP_Field::make(['type' => 'date']);",
],
[
'id' => 'time_field',
'type' => 'time',
'label' => 'Time — Время',
'desc' => 'Выбор времени (HTML5)',
'example_code' => "WP_Field::make(['type' => 'time']);",
],
[
'id' => 'datetime_field',
'type' => 'datetime-local',
'label' => 'DateTime — Дата и время',
'desc' => 'Выбор даты и времени (HTML5)',
'example_desc' => 'Использует нативный HTML5 datetime-local picker',
'example_code' => "WP_Field::make(['type' => 'datetime-local']);",
],
],
],
// Простые поля v2.1
[
'title' => '4. Простые поля v2.1 (9)',
'description' => 'UI компоненты и информационные элементы',
'fields' => [
array_merge([
'id' => 'switcher_field',
'type' => 'switcher',
'label' => 'Switcher — Переключатель',
'text_on' => 'Вкл',
'text_off' => 'Выкл',
'desc' => 'Красивый переключатель вкл/выкл',
'example_desc' => 'Современный UI переключатель с анимацией. Альтернатива обычному checkbox с более наглядным интерфейсом.',
'example_code' => "WP_Field::make([\n 'type' => 'switcher',\n 'text_on' => 'On',\n 'text_off' => 'Off'\n]);",
], $this->get_field_data('switcher')),
[
'id' => 'spinner_field_1',
'type' => 'spinner',
'label' => 'Spinner — Счётчик',
'min' => 0,
'max' => 100,
'step' => 1,
'desc' => 'max:100 | min:0 | step:1',
'example_code' => "WP_Field::make([\n 'type' => 'spinner',\n 'min' => 0,\n 'max' => 100,\n 'step' => 1\n]);",
],
[
'id' => 'spinner_field_2',
'type' => 'spinner',
'label' => 'Spinner',
'min' => 100,
'max' => 200,
'step' => 10,
'desc' => 'max:200 | min:100 | step:10',
'example_code' => "WP_Field::make([\n 'type' => 'spinner',\n 'min' => 100,\n 'max' => 200,\n 'step' => 10\n]);",
],
[
'id' => 'spinner_field_3',
'type' => 'spinner',
'label' => 'Spinner',
'min' => 0,
'max' => 1,
'step' => 0.1,
'unit' => 'px',
'desc' => 'max:1 | min:0 | step:0.1 | unit:px',
'example_code' => "WP_Field::make([\n 'type' => 'spinner',\n 'min' => 0,\n 'max' => 1,\n 'step' => 0.1,\n 'unit' => 'px'\n]);",
],
[
'id' => 'button_set_field',
'type' => 'button_set',
'label' => 'Button Set — Группа кнопок',
'options' => [
'left' => 'Слева',
'center' => 'По центру',
'right' => 'Справа',
],
'desc' => 'Выбор через кнопки',
'example_code' => "WP_Field::make([\n 'type' => 'button_set',\n 'options' => [...]\n]);",
],
[
'id' => 'slider_field',
'type' => 'slider',
'label' => 'Slider — Ползунок',
'min' => 0,
'max' => 100,
'step' => 1,
'show_value' => true,
'desc' => 'Ползунок с отображением значения',
'example_code' => "WP_Field::make([\n 'type' => 'slider',\n 'show_value' => true\n]);",
],
[
'id' => 'heading_field',
'type' => 'heading',
'label' => 'Heading — Заголовок',
'desc' => 'Информационный заголовок (не сохраняется)',
'example_code' => "WP_Field::make(['type' => 'heading']);",
],
[
'id' => 'notice_field',
'type' => 'notice',
'label' => 'Это информационное уведомление',
'notice_type' => 'info',
'desc' => 'Типы: info, success, warning, error',
'example_code' => "WP_Field::make([\n 'type' => 'notice',\n 'notice_type' => 'info'\n]);",
],
[
'id' => 'subheading_field',
'type' => 'subheading',
'label' => 'Subheading — Подзаголовок',
'desc' => 'Подзаголовок для группировки полей',
'example_code' => "WP_Field::make(['type' => 'subheading']);",
],
[
'id' => 'content_field',
'type' => 'content',
'label' => 'Content — Произвольный контент',
'content' => '<p>Это произвольный HTML контент. Можно использовать для инструкций, описаний и т.д.</p>',
'desc' => 'Вывод произвольного HTML',
'example_code' => "WP_Field::make([\n 'type' => 'content',\n 'content' => '<p>HTML...</p>'\n]);",
],
[
'id' => 'fieldset_field',
'type' => 'fieldset',
'label' => 'Fieldset — Группа полей',
'fields' => [
['id' => 'fs_text', 'type' => 'text', 'label' => 'Текст внутри fieldset'],
['id' => 'fs_checkbox', 'type' => 'checkbox', 'label' => 'Чекбокс внутри fieldset'],
],
'desc' => 'Группировка полей в fieldset',
'example_code' => "WP_Field::make([\n 'type' => 'fieldset',\n 'fields' => [...]\n]);",
],
],
],
// Композитные поля
[
'title' => '5. Композитные поля (2)',
'description' => 'Группировка и повторение полей',
'fields' => [
[
'id' => 'group_field',
'type' => 'group',
'label' => 'Group — Группа полей',
'fields' => [
['id' => 'group_name', 'type' => 'text', 'label' => 'Имя'],
['id' => 'group_email', 'type' => 'email', 'label' => 'Email'],
['id' => 'group_phone', 'type' => 'tel', 'label' => 'Телефон'],
],
'desc' => 'Группировка связанных полей',
'example_code' => "WP_Field::make([\n 'type' => 'group',\n 'fields' => [...]\n]);",
],
array_merge([
'id' => 'repeater_field',
'type' => 'repeater',