'town', 'hide_empty' => false, 'fields' => 'id=>slug', ]); if (is_array($terms) && in_array($first_segment, $terms, true)) { $resolved = $first_segment; } } if ($resolved === null) { $resolved = \apply_filters('wpmc_main_town_slug', null); if (!is_string($resolved) || $resolved === '') { $resolved = null; } } $resolved = \apply_filters('wpmc_current_town_slug', $resolved); if (!is_string($resolved) || $resolved === '') { $resolved = null; } self::$current_town_memo = $resolved; self::$current_town_resolved = true; return $resolved; } private static function first_path_segment(string $uri): ?string { $path = strtok($uri, '?'); if ($path === false) { return null; } $parts = array_values(array_filter(explode('/', $path), static fn(string $p) => $p !== '')); return $parts[0] ?? null; } public static function alt_get_field(string $selector, $post_id = false, bool $format_value = true) { $post_id = \apply_filters('wpmc_alt_get_field_post_id', $post_id, $selector); if (!\function_exists('get_field')) { return null; } $value = \get_field($selector, $post_id, $format_value); return is_string($value) ? \do_shortcode($value) : $value; } public static function remove_domain_link(string $url): string { $parsed = parse_url($url); if ($parsed === false || empty($parsed['scheme'])) { return $url; } $scheme = strtolower((string) $parsed['scheme']); if ($scheme !== 'http' && $scheme !== 'https') { return $url; } $path = $parsed['path'] ?? ''; $query = isset($parsed['query']) ? '?' . $parsed['query'] : ''; $fragment = isset($parsed['fragment']) ? '#' . $parsed['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; } }