jon-b
8/16/2016 - 8:15 AM

Check to see if current server is local/dev/staging

Check to see if current server is local/dev/staging

<?php 
/**
 * Check to see if current server is local/dev/staging
 *
 * Use if ( function_exists('s9_is_dev_server') && ( ! s9_is_dev_server() ) ) {}
 *
 * @return     boolean  ( description_of_the_return_value )
 */
function s9_is_dev_server() {
	$is_dev = false;
	if ( function_exists( 'is_wpe_snapshot' ) && is_wpe_snapshot() ) {
		$is_dev = true;
	} else {
		$url_parts = parse_url( htmlspecialchars( "//$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", ENT_QUOTES, 'UTF-8' ) );
		$host_parts = explode( '.', $url_parts['host'] );
		$host_parts = array_reverse( $host_parts );
		$dev_endings = array( 'dev', 'test', 'local' );
		if ( in_array( $host_parts[0], $dev_endings, true ) ) {
			$is_dev = true;
		}
	}
	return $is_dev;
}