|
13 | 13 |
|
14 | 14 | // Parse the domain and subdomain from the request |
15 | 15 | $domain = strtolower($_SERVER['HTTP_HOST'] ?? ''); |
16 | | - $base_domain = parse_url($wp_home, PHP_URL_HOST) . $nginx_port; |
| 16 | + $base_domain = parse_url($wp_home, PHP_URL_HOST); |
| 17 | + $base_domain_with_port = $base_domain . $nginx_port; |
17 | 18 | $subdomain = null; |
18 | 19 |
|
19 | 20 | // Extract the subdomain if it differs from the base domain |
20 | | - if (strpos(explode('.', $domain)[0], $base_domain) === false) { |
| 21 | + if (strpos(explode('.', $domain)[0], $base_domain_with_port) === false) { |
21 | 22 | $subdomain = explode('.', $domain)[0]; |
22 | 23 | } |
23 | 24 |
|
|
38 | 39 | // Set $current_site and $current_blog based on environment variables and dynamic values |
39 | 40 | $current_site = (object) [ |
40 | 41 | 'id' => $site_id, |
41 | | - 'domain' => $base_domain, |
| 42 | + 'domain' => $base_domain_with_port, |
42 | 43 | 'path' => Config::get('PATH_CURRENT_SITE') ?: '/', |
43 | 44 | 'blog_id' => $blog_id, |
44 | 45 | 'public' => 1, |
|
52 | 53 | $current_blog = (object) [ |
53 | 54 | 'blog_id' => $blog_id, |
54 | 55 | 'site_id' => $site_id, |
55 | | - 'domain' => $subdomain ? $subdomain . '.' . $base_domain : $base_domain, |
| 56 | + 'domain' => $subdomain ? $subdomain . '.' . $base_domain_with_port : $base_domain_with_port, |
56 | 57 | 'path' => Config::get('PATH_CURRENT_SITE') ?: '/', |
57 | 58 | 'public' => 1, |
58 | 59 | 'archived' => 0, |
|
62 | 63 | 'lang_id' => 0, |
63 | 64 | ]; |
64 | 65 |
|
| 66 | + // Set COOKIE_DOMAIN to handle subdomains dynamically |
| 67 | + $cookie_domain = $subdomain ? $subdomain . '.' . $base_domain : $base_domain; |
| 68 | + define('COOKIE_DOMAIN', $cookie_domain); |
| 69 | + |
65 | 70 | // Debugging log to confirm settings in development |
66 | 71 | if ($environment === 'development') { |
67 | 72 | error_log("SUNRISE: Detected subdomain '{$subdomain}', setting current_blog->domain to {$current_blog->domain}, blog_id to {$blog_id}, site_id to {$site_id}"); |
|
0 commit comments