From b967a3a59fd8ee177182ad83580811632ab61c60 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Sat, 16 May 2026 19:22:59 +0500 Subject: [PATCH] feat(wpmc S4): Helpers::index_town_alt_page_id reads ACF option --- includes/class-helpers.php | 10 ++++++++++ tests/HelpersTest.php | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/includes/class-helpers.php b/includes/class-helpers.php index 341a3a8..231e2f1 100644 --- a/includes/class-helpers.php +++ b/includes/class-helpers.php @@ -102,6 +102,16 @@ final class Helpers return $path . $query . $fragment; } + public static function index_town_alt_page_id(): ?int + { + if (!\function_exists('get_field')) { + return null; + } + $value = \get_field('index_town_alt', 'option'); + $id = (int) $value; + return $id > 0 ? $id : null; + } + public static function main_town_slug(): ?string { if (!\function_exists('get_field')) { diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index 7595d32..7fc2713 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -311,4 +311,24 @@ final class HelpersTest extends TestCase self::assertTrue(true); } + + public function test_index_town_alt_page_id_returns_int_when_option_set(): void + { + \Brain\Monkey\Functions\expect('get_field') + ->once() + ->with('index_town_alt', 'option') + ->andReturn(42); + + self::assertSame(42, Helpers::index_town_alt_page_id()); + } + + public function test_index_town_alt_page_id_returns_null_when_zero(): void + { + \Brain\Monkey\Functions\expect('get_field') + ->once() + ->with('index_town_alt', 'option') + ->andReturn(0); + + self::assertNull(Helpers::index_town_alt_page_id()); + } }