feat(wpmc S3): Helpers::get_term_by_slug with per-request cache

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vladimir Bryzgalov
2026-05-12 19:56:54 +05:00
parent 176d8e0c0b
commit 58838b0c19
3 changed files with 67 additions and 0 deletions
+10
View File
@@ -15,4 +15,14 @@ final class Helpers
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;
}
}