Skip to content

Instantly share code, notes, and snippets.

@kingkool68
Created October 12, 2015 18:23
Show Gist options
  • Save kingkool68/a4142b41a97d03b0db1a to your computer and use it in GitHub Desktop.
Save kingkool68/a4142b41a97d03b0db1a to your computer and use it in GitHub Desktop.
WordPress helper conditionals to run code in certain environments.
<?php
/**
* Helper conditionals to run code in certain environments.
*/
if ( ! defined( 'RH_ENV' ) ) {
$hostname = $_SERVER['HTTP_HOST'];
if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) {
$hostname = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
if ( strstr( $hostname, '.dev' ) ) {
define( 'RH_ENV', 'dev' );
} else {
define( 'RH_ENV', 'production' );
}
}
/**
* Is the enviornment production?
* @return boolean
*/
function rh_is_production() {
if ( 'production' === RH_ENV ) {
return true;
}
return false;
}
/**
* Alias of rh_is_production().
* @return boolean
*/
function rh_is_prod() {
return rh_is_production();
}
/**
* Is the environment staging?
* @return boolean
*/
function rh_is_staging() {
if ( 'staging' === RH_ENV ) {
return true;
}
return false;
}
/**
* Alias of rh_is_staging().
* @return boolean
*/
function rh_is_stage() {
return rh_is_staging();
}
/**
* Is the environment dev?
* @return boolean
*/
function rh_is_dev() {
if ( 'dev' === RH_ENV ) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment