Plugin Directory

Changeset 1948784


Ignore:
Timestamp:
09/28/2018 06:58:42 PM (7 years ago)
Author:
crimson090
Message:

Version 1.1

Location:
wp-environment-indicator/trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • wp-environment-indicator/trunk

    • Property svn:ignore set to
      deploy.sh
      README.md
      .git
      .gitignore
  • wp-environment-indicator/trunk/README.txt

    r1510281 r1948784  
    44Tags: environment, development, indicator, admin, administration, dashboard, production, staging
    55Requires at least: 3.0.1
    6 Tested up to: 4.6.1
    7 Stable tag: 1.0.0
     6Tested up to: 4.9.8
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1414
    1515Displays an indicator above the admin bar indicating the current environment. Useful for quickly determining which
    16 environment you are currently viewing. 
     16environment you are currently viewing.
    1717
    1818This only displays in the WordPress admin, not on the website itself.
     
    3737== Changelog ==
    3838
     39= 1.1 =
     40* Fixes to support different hosting environments such as docker
     41* Add a selection box for the banner color
     42
    3943= 1.0 =
    4044* Initial release
  • wp-environment-indicator/trunk/admin/class-wp-environment-indicator-admin.php

    r1510282 r1948784  
    3939     * @var      string    $version    The current version of this plugin.
    4040     */
    41     private $version;
     41    private $version;
     42
     43    private $hostName;
    4244
    4345    /**
     
    5153
    5254        $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    }
    5571
    5672    /**
     
    6076     */
    6177    public function enqueue_styles() {
    62 
    6378        /**
    6479         * Enqueues the admin style, but only if we're on the dev host
     
    7287         * class.
    7388         */
    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            }
    76101        }
    77102
     
    86111
    87112        /**
    88          * 
     113         *
    89114         *
    90115         * An instance of this class should be passed to the run() function
     
    127152        </form>
    128153    </div> <?php
    129     }   
     154    }
    130155
    131156    public function setup_sections() {
     
    135160    public function section_callback( $arguments ) {
    136161        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;
    138163    }
    139164
    140165    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' );
    142167        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' );
    143171    }
    144172
    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    }
    148190
    149191}
Note: See TracChangeset for help on using the changeset viewer.