feat(wpmc S4): OptionsPage::do_register registers routing field group

Also: add acf_add_options_page to acf-stubs.php; add translation-function
stubs to acf-stubs.php; fix TestCase::tearDown to call Patchwork::restoreAll()
in a finally block so that when('function_exists') routes are always cleaned up
even when Mockery::close() throws InvalidCountException.
This commit is contained in:
Vladimir Bryzgalov
2026-05-16 19:54:23 +05:00
parent 79de284f53
commit fc21fd1f06
4 changed files with 237 additions and 2 deletions
+107 -1
View File
@@ -16,6 +16,112 @@ final class OptionsPage
public static function do_register(): void
{
// Implementation in Task 8.
if (!\function_exists('acf_add_options_page')
|| !\function_exists('acf_add_local_field_group')) {
return;
}
\acf_add_options_page([
'page_title' => 'WP Multi City',
'menu_title' => 'WP Multi City',
'menu_slug' => self::PAGE_SLUG,
'capability' => 'manage_options',
'redirect' => false,
]);
\acf_add_local_field_group([
'key' => self::GROUP_KEY,
'title' => 'WPMultiCity / Routing',
'fields' => [
[
'key' => 'field_wpmc_main_town_slug',
'label' => __('Главный город (без префикса URL)', 'wp-multi-city'),
'name' => 'main_town_slug',
'type' => 'taxonomy',
'taxonomy' => 'town',
'field_type' => 'select',
'return_format' => 'object',
'allow_null' => 1,
'multiple' => 0,
'add_term' => 0,
],
[
'key' => 'field_wpmc_index_town_alt',
'label' => __('Главная для других городов', 'wp-multi-city'),
'name' => 'index_town_alt',
'type' => 'post_object',
'post_type' => ['page'],
'return_format' => 'id',
'allow_null' => 1,
'multiple' => 0,
],
[
'key' => 'field_wpmc_page_unic',
'label' => __('Клоны страниц', 'wp-multi-city'),
'name' => 'page_unic',
'type' => 'repeater',
'layout' => 'table',
'button_label' => __('Добавить клон', 'wp-multi-city'),
'sub_fields' => [
[
'key' => 'field_wpmc_page_unic_page_old',
'label' => __('Оригинал', 'wp-multi-city'),
'name' => 'page_old',
'type' => 'post_object',
'post_type' => ['page'],
'return_format' => 'id',
'allow_null' => 0,
'multiple' => 0,
],
[
'key' => 'field_wpmc_page_unic_page_new',
'label' => __('Клон', 'wp-multi-city'),
'name' => 'page_new',
'type' => 'post_object',
'post_type' => ['page'],
'return_format' => 'id',
'allow_null' => 0,
'multiple' => 0,
],
[
'key' => 'field_wpmc_page_unic_town',
'label' => __('Город', 'wp-multi-city'),
'name' => 'town',
'type' => 'taxonomy',
'taxonomy' => 'town',
'field_type' => 'select',
'return_format' => 'id',
'allow_null' => 0,
'multiple' => 0,
'add_term' => 0,
],
],
],
[
'key' => 'field_wpmc_page_no_rep',
'label' => __('Исключения из роутинга', 'wp-multi-city'),
'name' => 'page_no_rep',
'type' => 'repeater',
'layout' => 'table',
'button_label' => __('Добавить исключение', 'wp-multi-city'),
'sub_fields' => [
[
'key' => 'field_wpmc_page_no_rep_link',
'label' => __('Путь', 'wp-multi-city'),
'name' => 'link',
'type' => 'text',
'instructions' => __('Префикс URL, например /privacy/', 'wp-multi-city'),
],
],
],
],
'location' => [
[['param' => 'options_page', 'operator' => '==', 'value' => self::PAGE_SLUG]],
],
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'active' => true,
]);
}
}