term_id) ?? 0); } if (!$page_id) { $fallback = Helpers::index_town_alt_page_id(); if ($fallback === null) { return; } $page_id = $fallback; } self::install_query($page_id, $town_slug, true); return; } // Internal page handling lands in Task 13. } private static function strip_town_prefix(string $uri, string $town_slug): string { $path = strtok($uri, '?'); $query = (strpos($uri, '?') !== false) ? substr($uri, strpos($uri, '?')) : ''; $new_path = preg_replace('#^/' . preg_quote($town_slug, '#') . '(/|$)#', '/', (string) $path); return ($new_path ?? '/') . $query; } private static function is_root(string $url): bool { $path = strtok($url, '?'); return $path === '/' || $path === false || $path === ''; } private static function install_query(int $page_id, string $town_slug, bool $is_front_page): void { global $wp_query, $wp_the_query, $post; $post = \get_post($page_id); $wp_query = new \WP_Query(['page_id' => $page_id, 'town' => $town_slug]); $wp_query->is_page = true; if ($is_front_page) { $wp_query->is_front_page = true; } $wp_the_query = $wp_query; \status_header(200); } }