Created
October 12, 2015 18:23
-
-
Save kingkool68/a4142b41a97d03b0db1a to your computer and use it in GitHub Desktop.
WordPress helper conditionals to run code in certain environments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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