Skip to content

Instantly share code, notes, and snippets.

@dave1010 dave1010/wp-cli.php
Created Apr 26, 2011

What would you like to do?
Load WordPress from a CLI not in the global scope
// When loading WP from phpunit, phpunit doesn't run WP in the global scope.
// This breaks WP. This is an attempt to fix it.
function de_globalize_wp() {
// pretend this is apache
// I use $_SERVER['HTTP_HOST'] or a file called "host" to get the right DB settings
$_SERVER['HTTP_HOST'] = trim(file_get_contents(__DIR__ . '/host'));
$_SERVER["REMOTE_ADDR"] = 'localhost';
$GLOBALS[ '_wp_deprecated_widgets_callbacks' ] = array();
// WP assumes it's being loaded globally
global $wp_version;
global $PHP_SELF;
global $wp_embed;
global $wpdb;
global $wp_rewrite;
global $wp_the_query;
define( 'DOING_AJAX', true );
include 'wp-load.php';
echo "It actually worked!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.