I was once asked a question:
Is it possible to emulate a request in WP-CLI, so that all of the various globals are correctly populated when I start poking in
wp shell
?
The answer is “yes.”
- First, you need to specify the request URL when invoking
wp shell
. For example,wp shell --url=https://wildwolf.name/how-to-log-request-headers-with-nginx-and-njs/
- Then, inside the shell, you need to invoke the
function. It will parse the request and set all variables.wp()
- If you need to access a global variable, you need to run
global $variable_name;
first.
How to Emulate a Request in WP CLI Shell