Changeset 1948784
- Timestamp:
- 09/28/2018 06:58:42 PM (7 years ago)
- Location:
- wp-environment-indicator/trunk
- Files:
-
- 4 added
- 3 edited
-
. (modified) (1 prop)
-
README.txt (modified) (3 diffs)
-
admin/class-wp-environment-indicator-admin.php (modified) (7 diffs)
-
admin/css/dev-mode-red.svg (added)
-
admin/css/dev-mode-yellow.svg (added)
-
admin/css/wp-environment-indicator-admin-red.css (added)
-
admin/css/wp-environment-indicator-admin-yellow.css (added)
Legend:
- Unmodified
- Added
- Removed
-
wp-environment-indicator/trunk
-
Property
svn:ignore
set to
deploy.sh
README.md
.git
.gitignore
-
Property
svn:ignore
set to
-
wp-environment-indicator/trunk/README.txt
r1510281 r1948784 4 4 Tags: environment, development, indicator, admin, administration, dashboard, production, staging 5 5 Requires at least: 3.0.1 6 Tested up to: 4. 6.17 Stable tag: 1. 0.06 Tested up to: 4.9.8 7 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 14 14 15 15 Displays an indicator above the admin bar indicating the current environment. Useful for quickly determining which 16 environment you are currently viewing. 16 environment you are currently viewing. 17 17 18 18 This only displays in the WordPress admin, not on the website itself. … … 37 37 == Changelog == 38 38 39 = 1.1 = 40 * Fixes to support different hosting environments such as docker 41 * Add a selection box for the banner color 42 39 43 = 1.0 = 40 44 * Initial release -
wp-environment-indicator/trunk/admin/class-wp-environment-indicator-admin.php
r1510282 r1948784 39 39 * @var string $version The current version of this plugin. 40 40 */ 41 private $version; 41 private $version; 42 43 private $hostName; 42 44 43 45 /** … … 51 53 52 54 $this->plugin_name = $plugin_name; 53 $this->version = $version; 54 } 55 $this->version = $version; 56 $this->hostName = $this->get_host_name(); 57 } 58 59 private function get_host_name() { 60 $hostName = $_SERVER['HTTP_HOST']; 61 if (empty($hostName)) { 62 $hostName = $_SERVER['SERVER_NAME']; 63 } 64 if (empty($hostName)) { 65 $hostName = $_SERVER['VIRTUAL_HOST']; 66 } 67 68 return $hostName; 69 70 } 55 71 56 72 /** … … 60 76 */ 61 77 public function enqueue_styles() { 62 63 78 /** 64 79 * Enqueues the admin style, but only if we're on the dev host … … 72 87 * class. 73 88 */ 74 if ($_SERVER['SERVER_NAME'] == get_option('wpei_dev_hostname_field')) { 75 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-environment-indicator-admin.css', array(), $this->version, 'all' ); 89 90 $devServer = get_option('wpei_dev_hostname_field'); 91 $devServer = str_replace("http://", "", $devServer); 92 $devServer = str_replace("https://", "", $devServer); 93 94 if (strpos($devServer, $this->hostName) !== false) { 95 if (get_option('wpei_dev_hostname_color') == "yellow") { 96 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-environment-indicator-admin-yellow.css', array(), $this->version, 'all' ); 97 } 98 else { 99 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-environment-indicator-admin-red.css', array(), $this->version, 'all' ); 100 } 76 101 } 77 102 … … 86 111 87 112 /** 88 * 113 * 89 114 * 90 115 * An instance of this class should be passed to the run() function … … 127 152 </form> 128 153 </div> <?php 129 } 154 } 130 155 131 156 public function setup_sections() { … … 135 160 public function section_callback( $arguments ) { 136 161 echo '<p>Enter the host name of your development environment below. When visiting the site at this host name, an indicator will be added to the top of the WordPress admin.</p>'; 137 echo '<em>Current Host</em>: ' . $ _SERVER['SERVER_NAME'];162 echo '<em>Current Host</em>: ' . $this->hostName; 138 163 } 139 164 140 165 public function setup_fields() { 141 add_settings_field( 'wpei_dev_hostname_field', 'Development Host Name', array( $this, 'field_callback' ), 'wp_environment_indicator_fields', 'environment_urls_section' );166 add_settings_field( 'wpei_dev_hostname_field', 'Development Host Name', array( $this, 'hostname_field' ), 'wp_environment_indicator_fields', 'environment_urls_section' ); 142 167 register_setting( 'wp_environment_indicator_fields', 'wpei_dev_hostname_field' ); 168 169 add_settings_field( 'wpei_dev_hostname_color', 'Development Banner Color', array( $this, 'banner_color' ), 'wp_environment_indicator_fields', 'environment_urls_section' ); 170 register_setting( 'wp_environment_indicator_fields', 'wpei_dev_hostname_color' ); 143 171 } 144 172 145 public function field_callback( $arguments ) { 146 echo '<input name="wpei_dev_hostname_field" id="wpei_dev_hostname_field" type="text" value="' . get_option( 'wpei_dev_hostname_field' ) . '" />'; 147 } 173 public function hostname_field( $arguments ) { 174 echo '<input name="wpei_dev_hostname_field" id="wpei_dev_hostname_field" type="text" value="' . get_option( 'wpei_dev_hostname_field' ) . '" />'; 175 } 176 177 public function banner_color( $arguments ) { 178 echo '<select name="wpei_dev_hostname_color" id="wpei_dev_hostname_color">'; 179 if (get_option('wpei_dev_hostname_color') == 'red') { 180 echo '<option value="yellow">Yellow</option> 181 <option value="red" selected>Red</option>'; 182 } 183 else { 184 echo '<option value="yellow" selected>Yellow</option> 185 <option value="red">Red</option>'; 186 } 187 188 189 } 148 190 149 191 }
Note: See TracChangeset
for help on using the changeset viewer.