|
3 | 3 | Plugin Name: Stage Switcher |
4 | 4 | Plugin URI: http://roots.io/plugins/stage-switcher/ |
5 | 5 | Description: A WordPress plugin that allows you to switch between different environments from the admin bar. |
6 | | -Version: 1.0.1 |
| 6 | +Version: 1.0.2 |
7 | 7 | Author: Ben Word |
8 | 8 | Author URI: http://roots.io/ |
9 | 9 | License: MIT License |
@@ -42,17 +42,28 @@ function admin_bar_stage_switcher($admin_bar) { |
42 | 42 | 'href' => '#' |
43 | 43 | )); |
44 | 44 |
|
45 | | - $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://'; |
| 45 | + $host_bits = explode('.', $_SERVER['HTTP_HOST']); |
| 46 | + $is_ms_subdomain = (is_multisite() && defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL && count($host_bits) > 2); |
46 | 47 |
|
47 | 48 | foreach($stages as $stage => $url) { |
48 | 49 | if ($stage === $current_stage) { |
49 | 50 | continue; |
50 | 51 | } |
51 | 52 |
|
52 | | - $url .= str_replace($stages[$current_stage], '', $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
| 53 | + if ($is_ms_subdomain) { |
| 54 | + $subdomain = $host_bits[0]; |
| 55 | + $stage_host = parse_url($url, PHP_URL_HOST); |
| 56 | + $subd_stage_host = "$subdomain.$stage_host"; |
| 57 | + $url = str_replace($stage_host, $subd_stage_host, $url); |
| 58 | + $url = rtrim($url, '/') . $_SERVER['REQUEST_URI']; |
| 59 | + } else { |
| 60 | + $stage_scheme = parse_url($stages[$current_stage], PHP_URL_SCHEME); |
| 61 | + $cur_stage_base = str_replace("$stage_scheme://", '', $stages[$current_stage]); |
| 62 | + $url .= str_replace($cur_stage_base, '', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
| 63 | + } |
53 | 64 |
|
54 | 65 | $admin_bar->add_menu(array( |
55 | | - 'id' => $stage, |
| 66 | + 'id' => "stage_$stage", |
56 | 67 | 'parent' => 'environment', |
57 | 68 | 'title' => ucwords($stage), |
58 | 69 | 'href' => $url |
|
0 commit comments