wp eval
Executes arbitrary PHP code.
Global variables must be explicitly declared using the keyword global. This is because the code is executed within a method, not in the global scope.
Similar commands:
Source code of commands
Parameters
You can specify Global parameters and the following:
- {php-code}
- Code to be executed as a string.
- [--skip-wordpress]
- Execute the code without loading WordPress.
Usage
wp eval
Examples
# Show the wp-content directory. $ wp eval 'echo WP_CONTENT_DIR;' /var/www/wordpress/wp-content
# Generate a random int. $ wp eval 'echo rand();' --skip-wordpress 479620423