feat: add ACF field groups for all custom post types

This commit is contained in:
2026-04-03 01:09:21 +05:00
parent 37ddc9119d
commit 8c54edf25e
2 changed files with 326 additions and 0 deletions
@@ -0,0 +1,325 @@
<?php
/**
* ACF Local Field Groups for all custom post types.
*
* Registers field groups for: case, webinar, course, event, material.
*
* @package bitwms-child
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'acf/init', 'bitwms_register_acf_field_groups' );
function bitwms_register_acf_field_groups() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
// -------------------------------------------------------------------------
// 1. Кейсы (case)
// -------------------------------------------------------------------------
acf_add_local_field_group( array(
'key' => 'group_case_fields',
'title' => 'Поля кейса',
'fields' => array(
array(
'key' => 'field_case_client',
'label' => 'Клиент',
'name' => 'case_client',
'type' => 'text',
'required' => 1,
),
array(
'key' => 'field_case_industry',
'label' => 'Отрасль',
'name' => 'case_industry',
'type' => 'text',
),
array(
'key' => 'field_case_task',
'label' => 'Задача',
'name' => 'case_task',
'type' => 'wysiwyg',
'toolbar' => 'basic',
),
array(
'key' => 'field_case_solution',
'label' => 'Решение',
'name' => 'case_solution',
'type' => 'wysiwyg',
'toolbar' => 'basic',
),
array(
'key' => 'field_case_result',
'label' => 'Результат',
'name' => 'case_result',
'type' => 'wysiwyg',
'toolbar' => 'basic',
),
array(
'key' => 'field_case_quote',
'label' => 'Цитата',
'name' => 'case_quote',
'type' => 'textarea',
'rows' => 3,
),
array(
'key' => 'field_case_gallery',
'label' => 'Галерея',
'name' => 'case_gallery',
'type' => 'gallery',
'return_format' => 'array',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'case',
),
),
),
) );
// -------------------------------------------------------------------------
// 2. Вебинары (webinar)
// -------------------------------------------------------------------------
acf_add_local_field_group( array(
'key' => 'group_webinar_fields',
'title' => 'Поля вебинара',
'fields' => array(
array(
'key' => 'field_webinar_date',
'label' => 'Дата и время',
'name' => 'webinar_date',
'type' => 'date_time_picker',
'required' => 1,
'display_format' => 'd.m.Y H:i',
'return_format' => 'Y-m-d H:i:s',
),
array(
'key' => 'field_webinar_speaker',
'label' => 'Спикер',
'name' => 'webinar_speaker',
'type' => 'text',
),
array(
'key' => 'field_webinar_status',
'label' => 'Статус',
'name' => 'webinar_status',
'type' => 'select',
'choices' => array(
'upcoming' => 'Анонс',
'past' => 'Прошёл',
),
'default_value' => 'upcoming',
),
array(
'key' => 'field_webinar_video',
'label' => 'Видеозапись',
'name' => 'webinar_video',
'type' => 'url',
'conditional_logic' => array(
array(
array(
'field' => 'field_webinar_status',
'operator' => '==',
'value' => 'past',
),
),
),
),
array(
'key' => 'field_webinar_presentation',
'label' => 'Презентация',
'name' => 'webinar_presentation',
'type' => 'file',
'return_format' => 'url',
'conditional_logic' => array(
array(
array(
'field' => 'field_webinar_status',
'operator' => '==',
'value' => 'past',
),
),
),
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'webinar',
),
),
),
) );
// -------------------------------------------------------------------------
// 3. Курсы (course)
// -------------------------------------------------------------------------
acf_add_local_field_group( array(
'key' => 'group_course_fields',
'title' => 'Поля курса',
'fields' => array(
array(
'key' => 'field_course_program',
'label' => 'Программа',
'name' => 'course_program',
'type' => 'wysiwyg',
'toolbar' => 'full',
),
array(
'key' => 'field_course_duration',
'label' => 'Длительность',
'name' => 'course_duration',
'type' => 'text',
'placeholder' => 'Например: 2 дня (16 часов)',
),
array(
'key' => 'field_course_format',
'label' => 'Формат',
'name' => 'course_format',
'type' => 'select',
'choices' => array(
'online' => 'Онлайн',
'offline' => 'Очно',
'mixed' => 'Смешанный',
),
),
array(
'key' => 'field_course_price',
'label' => 'Цена',
'name' => 'course_price',
'type' => 'text',
'placeholder' => 'Например: 25 000 руб.',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'course',
),
),
),
) );
// -------------------------------------------------------------------------
// 4. Мероприятия (event)
// -------------------------------------------------------------------------
acf_add_local_field_group( array(
'key' => 'group_event_fields',
'title' => 'Поля мероприятия',
'fields' => array(
array(
'key' => 'field_event_date',
'label' => 'Дата и время',
'name' => 'event_date',
'type' => 'date_time_picker',
'required' => 1,
'display_format' => 'd.m.Y H:i',
'return_format' => 'Y-m-d H:i:s',
),
array(
'key' => 'field_event_location',
'label' => 'Место проведения',
'name' => 'event_location',
'type' => 'text',
),
array(
'key' => 'field_event_format',
'label' => 'Формат',
'name' => 'event_format',
'type' => 'select',
'choices' => array(
'online' => 'Онлайн',
'offline' => 'Очно',
'mixed' => 'Смешанный',
),
),
array(
'key' => 'field_event_program',
'label' => 'Программа',
'name' => 'event_program',
'type' => 'wysiwyg',
'toolbar' => 'basic',
),
array(
'key' => 'field_event_registration_url',
'label' => 'Ссылка на регистрацию',
'name' => 'event_registration_url',
'type' => 'url',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'event',
),
),
),
) );
// -------------------------------------------------------------------------
// 5. Материалы (material)
// -------------------------------------------------------------------------
acf_add_local_field_group( array(
'key' => 'group_material_fields',
'title' => 'Поля материала',
'fields' => array(
array(
'key' => 'field_material_file',
'label' => 'Файл',
'name' => 'material_file',
'type' => 'file',
'return_format' => 'array',
),
array(
'key' => 'field_material_file_type',
'label' => 'Тип файла',
'name' => 'material_file_type',
'type' => 'select',
'choices' => array(
'pdf' => 'PDF',
'video' => 'Видео',
'checklist' => 'Чек-лист',
'excel' => 'Excel',
'other' => 'Другое',
),
),
array(
'key' => 'field_material_gated',
'label' => 'Закрытый доступ',
'name' => 'material_gated',
'type' => 'true_false',
'default_value' => 0,
'ui' => 1,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'material',
),
),
),
) );
}