feat(wpmc S4): Helpers::main_town_slug reads ACF option
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user