fc21fd1f06
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.
128 lines
5.5 KiB
PHP
128 lines
5.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity;
|
|
|
|
final class OptionsPage
|
|
{
|
|
public const PAGE_SLUG = 'wp-multi-city';
|
|
public const GROUP_KEY = 'group_wpmc_routing';
|
|
|
|
public static function register(): void
|
|
{
|
|
\add_action('acf/init', [self::class, 'do_register']);
|
|
\add_filter('wpmc_main_town_slug', [Helpers::class, 'main_town_slug'], 5);
|
|
}
|
|
|
|
public static function do_register(): void
|
|
{
|
|
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,
|
|
]);
|
|
}
|
|
}
|