forked from wp-cli/wp-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-cli.php
executable file
·76 lines (63 loc) · 2.09 KB
/
wp-cli.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env php
<?php
if(PHP_SAPI !== 'cli') {
die('Only cli access');
}
// Define the WordPress location
if(is_readable($_SERVER['PWD'] . '/../wp-load.php')) {
define('WP_ROOT', $_SERVER['PWD'] . '/../');
}
else {
define('WP_ROOT', $_SERVER['PWD'] . '/');
}
// Define the wp-cli location
define('WP_CLI_ROOT', __DIR__ . '/');
// Set a constant that can be used to check if we are running wp-cli or not
define('WP_CLI', true);
// Include the wp-cli classes
include WP_CLI_ROOT.'class-wp-cli.php';
include WP_CLI_ROOT.'class-wp-cli-command.php';
// Include the command line tools, taken from here: https://github.com/jlogsdon/php-cli-tools
include WP_CLI_ROOT.'php-cli-tools/lib/cli/cli.php';
\cli\register_autoload();
// Taken from https://github.com/88mph/wpadmin/blob/master/wpadmin.php
// Does the user have access to read the directory? If so, allow them to use the command line tool.
if(true == is_readable(WP_ROOT . 'wp-load.php')){
// Load WordPress libs.
require_once(WP_ROOT . 'wp-load.php');
require_once(ABSPATH . WPINC . '/template-loader.php');
require_once(ABSPATH . 'wp-admin/includes/admin.php');
}
else {
WP_CLI::error('Either this is not a WordPress document root or you do not have permission to administer this site.');
exit();
}
// Load all internal commands
foreach (glob(WP_CLI_ROOT.'/commands/internals/*.php') as $filename) {
include $filename;
}
// Load all plugin commands
foreach (glob(WP_CLI_ROOT.'/commands/community/*.php') as $filename) {
include $filename;
}
// Get the cli arguments
$arguments = $GLOBALS['argv'];
// Remove the first entry
array_shift($arguments);
// Get the command
$command = array_shift($arguments);
// Check if there are commands installed
if(empty(WP_CLI::$commands)) {
WP_CLI::error('No commands installed');
WP_CLI::line();
WP_CLI::line('Visit the wp-cli page on github on more information on how to install commands.');
exit();
}
// Try to load the class, otherwise it's an Unknown command
elseif(isset(WP_CLI::$commands[$command])) {
new WP_CLI::$commands[$command]($arguments);
}
// Show the general help for wp-cli
else {
WP_CLI::generalHelp();
}