Skip to content

Instantly share code, notes, and snippets.

@em-piguet
Last active February 8, 2017 17:38
Show Gist options
  • Save em-piguet/e056362fe863265cf454e92d532fa572 to your computer and use it in GitHub Desktop.
Save em-piguet/e056362fe863265cf454e92d532fa572 to your computer and use it in GitHub Desktop.
Helper for dev in Wp
<?php
/*
* Returns true if we are working on a development server, determined by server's
* hostname. Will generate an error if run on an unknown host.
*/
function isdev()
{
$isdev = null;
// don't run function body more than once
if( null !== $isdev ) {
return $isdev;
}
// prefer HOSTNAME in the environment, which will be set in Apache.
// use `uname -n' as a backup.
if( isset( $_ENV['HOSTNAME'] ) ) {
$hostname = $_ENV['HOSTNAME'];
} else {
$hostname = php_uname("n");
}
//echo '$hostname '.$hostname;
switch( $hostname ) {
case 'mydomain.ch/':
case 'www.mydomain.ch/':
$isdev = false; break;
case 'dev.domain':
case 'MacBook-Air-de-xxx-2.local':
case 'MacBook-Pro-de-yyy.local': $isdev = true; break;
default: trigger_error( 'HOSTNAME is set to an unknown value', E_USER_ERROR );
}
return $isdev;
}
/* example use */
if( isdev() ) {
$url = 'https://cloud.typography.com/xxx/7943572/css/fonts.css' ; // dev server
}else{
$url = 'https://cloud.typography.com/xxx/6189752/css/fonts.css' ; // prod server
}
wp_enqueue_style('font-css', $url, array('main-stylesheet'), '',all);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment