Created
August 27, 2013 15:40
-
-
Save coolamit/6355248 to your computer and use it in GitHub Desktop.
Code to plug in wp-config.php before any constants are defined, so that wp-cli doesnt throw any errors as $_SERVER wouldn't be available when running a wp-cli script
This file contains hidden or 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 | |
//initial code to set error reporting, xdebug customization etc. | |
if ( defined('WP_CLI') && WP_CLI ) { | |
if( empty( WP_CLI::get_runner()->config['url'] ) ) { | |
error_log( "You need to set url." ); | |
exit; | |
} | |
$_SERVER['SERVER_NAME'] = 'http://' . str_replace( array( 'https://', 'http://' ), '', WP_CLI::get_runner()->config['url'] ); | |
$_SERVER['SERVER_NAME'] = parse_url( $_SERVER['SERVER_NAME'], PHP_URL_HOST ); | |
if( empty( $_SERVER['SERVER_NAME'] ) ) { | |
error_log( "You need to set a site url." ); | |
exit; | |
} | |
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36'; | |
} | |
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME']); | |
// rest of the stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment