feat(wpmc S4): Helpers::main_town_slug reads ACF option

This commit is contained in:
Vladimir Bryzgalov
2026-05-16 19:21:31 +05:00
parent 0565357b5e
commit f4184a7777
2 changed files with 32 additions and 0 deletions
+12
View File
@@ -99,4 +99,16 @@ final class Helpers
$fragment = isset($parsed['fragment']) ? '#' . $parsed['fragment'] : ''; $fragment = isset($parsed['fragment']) ? '#' . $parsed['fragment'] : '';
return $path . $query . $fragment; return $path . $query . $fragment;
} }
public static function main_town_slug(): ?string
{
if (!\function_exists('get_field')) {
return null;
}
$value = \get_field('main_town_slug', 'option');
if ($value instanceof \WP_Term) {
return $value->slug !== '' ? $value->slug : null;
}
return is_string($value) && $value !== '' ? $value : null;
}
} }
+20
View File
@@ -211,4 +211,24 @@ final class HelpersTest extends TestCase
// remove_domain_link is pure (no WP function dependencies) — exercise the proxy. // remove_domain_link is pure (no WP function dependencies) — exercise the proxy.
self::assertSame('/foo/', wpmc_remove_domain_link('https://site.com/foo/')); self::assertSame('/foo/', wpmc_remove_domain_link('https://site.com/foo/'));
} }
public function test_main_town_slug_reads_option_via_acf(): void
{
\Brain\Monkey\Functions\expect('get_field')
->once()
->with('main_town_slug', 'option')
->andReturn('spb');
self::assertSame('spb', Helpers::main_town_slug());
}
public function test_main_town_slug_returns_null_when_option_empty(): void
{
\Brain\Monkey\Functions\expect('get_field')
->once()
->with('main_town_slug', 'option')
->andReturn(false);
self::assertNull(Helpers::main_town_slug());
}
} }