58838b0c19
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
813 B
PHP
29 lines
813 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity;
|
|
|
|
final class Helpers
|
|
{
|
|
private static ?string $current_town_memo = null;
|
|
private static bool $current_town_resolved = false;
|
|
private static array $term_cache = [];
|
|
|
|
public static function reset_cache(): void
|
|
{
|
|
self::$current_town_memo = null;
|
|
self::$current_town_resolved = false;
|
|
self::$term_cache = [];
|
|
}
|
|
|
|
public static function get_term_by_slug(string $slug, string $taxonomy = 'town'): ?\WP_Term
|
|
{
|
|
$key = $taxonomy . '|' . $slug;
|
|
if (array_key_exists($key, self::$term_cache)) {
|
|
return self::$term_cache[$key];
|
|
}
|
|
$term = \get_term_by('slug', $slug, $taxonomy);
|
|
return self::$term_cache[$key] = ($term instanceof \WP_Term) ? $term : null;
|
|
}
|
|
}
|