forked from wp-cli/eval-command
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEval_Command.php
More file actions
41 lines (36 loc) · 861 Bytes
/
Eval_Command.php
File metadata and controls
41 lines (36 loc) · 861 Bytes
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
<?php
use WP_CLI\Utils;
class Eval_Command extends WP_CLI_Command {
/**
* Executes arbitrary PHP code.
*
* Note: because code is executed within a method, global variables need
* to be explicitly globalized.
*
* ## OPTIONS
*
* <php-code>
* : The code to execute, as a string.
*
* [--skip-wordpress]
* : Execute code without loading WordPress.
*
* ## EXAMPLES
*
* # Display WordPress content directory.
* $ wp eval 'echo WP_CONTENT_DIR;'
* /var/www/wordpress/wp-content
*
* # Generate a random number.
* $ wp eval 'echo rand();' --skip-wordpress
* 479620423
*
* @when before_wp_load
*/
public function __invoke( $args, $assoc_args ) {
if ( null === Utils\get_flag_value( $assoc_args, 'skip-wordpress' ) ) {
WP_CLI::get_runner()->load_wordpress();
}
eval( $args[0] );
}
}