Created
August 11, 2014 16:47
-
-
Save gmutschler/51f8835c779d5b81c3bb to your computer and use it in GitHub Desktop.
Detect if the current wordpress is in production stage. Usefull to loas minified file on prod.
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 | |
function is_production(){ | |
// Define Environments | |
$environments = array( | |
'local' => array('.local', 'local.','localhost','127.0.0.1'), | |
'development' => 'dev.', | |
'staging' => 'stage.', | |
'preview' => 'preview.', | |
); | |
// Get Server name | |
$server_name = $_SERVER['SERVER_NAME']; | |
foreach($environments AS $key => $env){ | |
if(is_array($env)){ | |
foreach ($env as $option){ | |
if(stristr($server_name, $option)){ | |
define('ENVIRONMENT', $key); | |
break 2; | |
} | |
} | |
} else { | |
if(stristr($server_name, $env)){ | |
define('ENVIRONMENT', $key); | |
break; | |
} | |
} | |
} | |
// If no environment is set default to production | |
if(!defined('ENVIRONMENT')) define('ENVIRONMENT', 'production'); | |
if(ENVIRONMENT == 'production'){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment