Skip to content

Instantly share code, notes, and snippets.

@gmutschler
Created August 11, 2014 16:47
Show Gist options
  • Save gmutschler/51f8835c779d5b81c3bb to your computer and use it in GitHub Desktop.
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.
<?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