-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcli-load.php
63 lines (48 loc) · 1.96 KB
/
cli-load.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Load WordPress for use in commandline scripts and shells
**/
if ( !defined('STDIN') )
throw new Exception("Please run this script from the command line.");
# Make sure errors get to the user
ini_set( 'display_errors', 'stderr' );
# Root path for this project
define( 'PROJECT_PATH', dirname( __DIR__ ) );
//define('DOING_AJAX', true);
# Don't try to process this like a request
define('WP_USE_THEMES', false);
$settings = get_project_settings();
# Spoof some http request stuff
$_SERVER["HTTP_HOST"] = $settings['install']['hostname'];
$_SERVER["SERVER_NAME"] = $settings['install']['hostname'];
$_SERVER["REQUEST_METHOD"] = "GET";
if ( empty( $_SERVER["REQUEST_URI"] ) )
$_SERVER["REQUEST_URI"] = "/cli";
# Set the ABSPATH so WordPress can find its files. Check if we're a
# traditionally organized project, or a fancy project.
if ( is_dir( PROJECT_PATH . '/wordpress' ) )
define( 'ABSPATH', PROJECT_PATH . '/wordpress/' );
else
define( 'ABSPATH', PROJECT_PATH . '/' );
if ( ! defined('WP_SITEURL') )
define( 'WP_SITEURL', "http://".$settings['install']['hostname'] );
// define('WP_ADMIN', TRUE);
# Load WordPress!
if ( file_exists( PROJECT_PATH . '/wp-config.php' ) )
require_once( PROJECT_PATH . '/wp-config.php' );
/**
* Load a settings json file and return the associative array of stuff
**/
function get_project_settings() {
# Figure out if we're running in development, staging or production
if ( isset($_SERVER['DEPLOYMENT_TARGET']) )
$settings_file = $_SERVER['DEPLOYMENT_TARGET'] . '_settings.json';
else $settings_file = 'development_settings.json';
# Load our settings JSON file for this deployment environment
$settings_path = PROJECT_PATH . '/data/' . $settings_file;
$settings = json_decode( file_get_contents( $settings_path ), true );
# Catch JSON errors
if ( $settings == NULL )
throw new Exception( "Settings file '$settings_path' could not be parsed\n" );
return $settings;
}