Changeset 2579683
- Timestamp:
- 08/07/2021 01:18:18 PM (5 years ago)
- Location:
- devstage/trunk
- Files:
-
- 2 edited
-
devstage.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
devstage/trunk/devstage.php
r2458333 r2579683 5 5 Description: Simplest admin bar indicator whether you are in development, staging or live environment. 6 6 Author: Weblings.co 7 Version: 1. 0.67 Version: 1.1.0 8 8 Author URI: https://www.weblings.co 9 9 */ 10 10 11 11 12 // Enqueue plugin scripts and styles 12 13 /** 14 * Enqueue plugin scripts and styles 15 */ 13 16 function devstage_styles_and_scripts() { 14 17 wp_enqueue_style('devstage', plugins_url('assets/css/devstage.css', __FILE__)); … … 24 27 25 28 26 // Mark WP admin bar on ://dev. and ://staging. enviroments 29 /** 30 * Generated by the WordPress Option Page generator 31 * at http://jeremyhixon.com/wp-tools/option-page/ 32 */ 33 34 class DevStage { 35 private $devstage_options; 36 37 public function __construct() { 38 add_action( 'admin_menu', array( $this, 'devstage_add_plugin_page' ) ); 39 add_action( 'admin_init', array( $this, 'devstage_page_init' ) ); 40 } 41 42 public function devstage_add_plugin_page() { 43 add_options_page( 44 'DevStage', // page_title 45 'DevStage', // menu_title 46 'manage_options', // capability 47 'devstage', // menu_slug 48 array( $this, 'devstage_create_admin_page' ) // function 49 ); 50 } 51 52 public function devstage_create_admin_page() { 53 $this->devstage_options = get_option( 'devstage_option_name' ); ?> 54 55 <div class="wrap"> 56 <h2>DevStage</h2> 57 <p>Only need to set the corresponding field if you are in the same environment. 58 <br><br> 59 Include the part between the protocol and the directory path: https://<strong><span style="background:white;padding:1px 4px;">www.domain.com</span></strong>/something/index.html 60 <br><br> 61 You can leave the field empty if you are using <strong><span style="background:white;padding:1px 4px;">://dev.</span></strong> or <strong><span style="background:white;padding:1px 4px;">://staging.</span></strong> subdomain for your dev or staging environment, respectively. In that case the plugin is already working for you. 62 </p> 63 <?php settings_errors(); ?> 64 65 <form method="post" action="options.php"> 66 <?php 67 settings_fields( 'devstage_option_group' ); 68 do_settings_sections( 'devstage-admin' ); 69 submit_button(); 70 ?> 71 </form> 72 </div> 73 <?php } 74 75 public function devstage_page_init() { 76 register_setting( 77 'devstage_option_group', // option_group 78 'devstage_option_name', // option_name 79 array( $this, 'devstage_sanitize' ) // sanitize_callback 80 ); 81 82 add_settings_section( 83 'devstage_setting_section', // id 84 'Settings', // title 85 array( $this, 'devstage_section_info' ), // callback 86 'devstage-admin' // page 87 ); 88 89 add_settings_field( 90 'development_environment_domain_0', // id 91 'Development environment domain', // title 92 array( $this, 'development_environment_domain_0_callback' ), // callback 93 'devstage-admin', // page 94 'devstage_setting_section' // section 95 ); 96 97 add_settings_field( 98 'staging_environment_domain_1', // id 99 'Staging environment domain', // title 100 array( $this, 'staging_environment_domain_1_callback' ), // callback 101 'devstage-admin', // page 102 'devstage_setting_section' // section 103 ); 104 } 105 106 public function devstage_sanitize($input) { 107 $sanitary_values = array(); 108 if ( isset( $input['development_environment_domain_0'] ) ) { 109 $sanitary_values['development_environment_domain_0'] = sanitize_text_field( $input['development_environment_domain_0'] ); 110 } 111 112 if ( isset( $input['staging_environment_domain_1'] ) ) { 113 $sanitary_values['staging_environment_domain_1'] = sanitize_text_field( $input['staging_environment_domain_1'] ); 114 } 115 116 return $sanitary_values; 117 } 118 119 public function devstage_section_info() { 120 121 } 122 123 public function development_environment_domain_0_callback() { 124 printf( 125 '<input class="regular-text" type="text" placeholder="use this field on dev env only" name="devstage_option_name[development_environment_domain_0]" id="development_environment_domain_0" value="%s">', 126 isset( $this->devstage_options['development_environment_domain_0'] ) ? esc_attr( $this->devstage_options['development_environment_domain_0']) : '' 127 ); 128 } 129 130 public function staging_environment_domain_1_callback() { 131 printf( 132 '<input class="regular-text" type="text" placeholder="use this field on staging env only" name="devstage_option_name[staging_environment_domain_1]" id="staging_environment_domain_1" value="%s">', 133 isset( $this->devstage_options['staging_environment_domain_1'] ) ? esc_attr( $this->devstage_options['staging_environment_domain_1']) : '' 134 ); 135 } 136 137 } 138 if ( is_admin() ) 139 $devstage = new DevStage(); 140 141 /* 142 * Retrieve this value with: 143 * $devstage_options = get_option( 'devstage_option_name' ); // Array of All Options 144 * $development_environment_domain_0 = $devstage_options['development_environment_domain_0']; // development environment domain 145 * $staging_environment_domain_1 = $devstage_options['staging_environment_domain_1']; // staging environment domain 146 */ 147 148 149 150 /** 151 * DevStage logic 152 */ 27 153 function dev_and_staging($admin_bar){ 28 154 29 $url = '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 155 $devstage_options = get_option( 'devstage_option_name' ); // Array of All Options 156 $development_environment_domain_0 = $devstage_options['development_environment_domain_0']; // development environment domain 157 $staging_environment_domain_1 = $devstage_options['staging_environment_domain_1']; // staging environment domain 158 $urlAuto = '://' . $_SERVER['HTTP_HOST']; 159 $urlManual = $_SERVER['HTTP_HOST']; 30 160 31 161 // Dev 32 if (strpos($url ,'://dev') !== false) {162 if (strpos($urlAuto,'://dev') !== false || $urlManual == $devstage_options['development_environment_domain_0']) { 33 163 $admin_bar->add_menu( array( 34 164 'id' => 'dev', … … 37 167 )); 38 168 // STAGING 39 } elseif (strpos($url ,'://staging') !== false) {169 } elseif (strpos($urlAuto,'://staging') !== false || $urlManual == $devstage_options['staging_environment_domain_1']) { 40 170 $admin_bar->add_menu( array( 41 171 'id' => 'staging', … … 53 183 } 54 184 add_action('admin_bar_menu', 'dev_and_staging'); 185 186 187 188 /** 189 * Add settings link under plugin on plugin screen 190 */ 191 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'devstage_settings_link' ); 192 function devstage_settings_link( $links ) { 193 // Build and escape the URL. 194 $url = esc_url( add_query_arg( 195 'page', 196 'devstage', 197 get_admin_url() . 'options-general.php' 198 ) ); 199 // Create the link. 200 $settings_link = "<a href='$url'>" . __( 'Settings' ) . '</a>'; 201 // Adds the link to the end of the array. 202 array_unshift( 203 $links, 204 $settings_link 205 ); 206 return $links; 207 } -
devstage/trunk/readme.txt
r2579394 r2579683 12 12 == Description == 13 13 14 Simplest admin bar indicator created by [Weblings](https://www.weblings.co/), to show whether you are in Development, Staging or Live environment. 15 Make sure your development and staging environment's url starts with '://dev' and '://staging' respectively. In every other case the the plugin marks the page as it is a Live environment. 14 Simplest admin bar indicator created by [Weblings](https://www.weblings.co/), to easily recognise whether you are in Development, Staging or Live environment. 16 15 17 16 == Installation == … … 19 18 1- Download the plugin. 20 19 2- Upload and activate the plugin through WordPress admin "Plugin" tab. 20 3- Check plugin settings under Settings => DevStage 21 21 22 22
Note: See TracChangeset
for help on using the changeset viewer.