This is the default behavior of WP-CLI’s built-in PHP REPL. If you look at the wp shell documentation, it shows that you can also use the Boris or PsySH PHP REPLs.
The Boris REPL does not seem to be actively maintained; however the PsySH REPL has fairly recent maintenance, and it fixes the problem that you’re experiencing.
The easiest way to integrate PsySH with WP-CLI is to use the wp-cli-psysh plugin:
# Make sure WP-CLI is up to date
wp cli update
# Install the plugin
wp package install [email protected]:schlessera/wp-cli-psysh.git
After installing the plugin, running wp shell should show you a PsySH header that’s similar to this:
$ wp shell
Psy Shell v0.9.9 (PHP 7.3.1-1+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>>
Related Posts:
- Detect if WP is running under WP-CLI
- wp-cli Enabling Maintainance Mode
- WP-CLI Cannot Connect to Database due to Vagrant
- WP-CLI Process Killed
- wp-cli commands do nothing, return nothing
- How do I clone or duplicate a post with the WordPress Command Line Interface WP-CLI?
- wp-cli doesn’t find and wordpress installation
- WP-CLI :: Cannot installing plugin as www-data
- wp-cli import theme sample data
- Export list of users with first and lastname in WP-CLI
- What could cause WP-CLI search-replace to not replace all instances of a string?
- Using Travis CI to run unit tests and running phpunit locally [closed]
- Revert WordPress default options after a PHPUnit test has run
- Can I create multiple pages at once using WP-CLI?
- wp-cli create post and media import
- Import Media To CPT with CLI & Filter Custom Taxonomy
- wp-cli with MAMP shows sh: mysql: command not found
- What is the difference between the Package Language and the Site Language?
- PHP warning are displaying when using WP CLI [closed]
- How do I update a nested option?
- Is it possible to use WP-CLI via PHP-framework?
- WP-CLI with theme: Uncaught Error: Class ‘WP_CLI’ not found
- WPCLI search and replace variants for all tables
- What tools respect `.distignore`?
- WP-CLI Get Site ID from its url
- WP-CLI alias: connect with ssh proxy
- Ask WP-CLI latest core WordPress version released
- How to change a post attribute to homepage using WP CLI?
- WP-CLI sudden empty response
- How to get all posts related to a term with WP-CLI?
- WP CLI: there has been critical error
- How to verify a correct wp-cli installation?
- How can I add an RSS widget using WP-CLI?
- MAMP PRO WP-CLI Error: Error establishing a database connection
- Shortest way to install WP-CLI
- “Class ‘Phar’ not found” error setting up WP-CLI with Cygwin
- Uninstall WP-CLI
- Running WP-CLI without SSH
- Is it possible to delete a range of posts by ID with WP-CLI?
- Get last published post in WordPress using wp-cli
- WP Cli will not execute on Windows
- Formatting messed up when piping wp commands
- Where do the files of a custom WP CLI Command reside?
- wpcli: Error on post_content or post_title if accents
- wp-cli configuration in php?
- Lock User and Enforce Password change via wp-cli
- How to use wp db export and import together?
- BackupBuddy WP CLI Invalid Profile Error
- How to find what pages/posts contain a particular reusable block?
- How can I search and replace by post type?
- Only the WP CLI command, wp –info, runs under my cPanel account
- Error establishing a database connection when running phpunit
- Set Site Icon programmatically (eg. using `wp cli`)
- How to rename default category name and slug using WP CLI?
- Resetting internal WordPress state during its cycle
- How do I add HTML code to a widget with wp-cli?
- Wildcard for wp-cli search-replace
- Update BackupBuddy with WP-CLI
- Is resetting post data necessary with custom WP_CLI commands?
- Get media url (featured image) with wp-cli
- Can I use wp-cli to create posts with a custom post types?
- WP CLI: search and replace specific directory name of URL
- WP-CLI plugin install causes PHP fatal error – Using $this when not in object context
- How to delete a single post using wp cli in command line?
- Adding content from file with wp post create
- WP CLI allowed fields?
- WP-CLI unable to recongnise PHP server / environment variables on Ubuntu
- WP-CLI media import error
- How to run wp cli from a wp hook?
- wp-cli PHP Notice after moving server behind load balancer
- Is it possible to view WP documentation within the WordPress shell?
- Userless db-only wordpress instalation
- WPCLI doesn’t recognize the site
- One-click WP site generation wih wp-cli on Windows
- Combine WPCLI commands for plugin installation and activation?
- Add passwords to config.yml to manage multiple sites
- What user should I use for wp-cli on Ubuntu VPS [closed]
- WP-CLI mysteriously stopping while downloading the core [closed]
- WP-CLI: Does “wp post create” will create post normally and will ping to Ping Service?
- Mocking WP_CLI static methods in unit tests
- How to add an array to a command “wp config set”?
- WP-CLI: detect altered core files and restore them automatically
- wp-cli core install unknown: fatal: file /etc/postfix/main.cf: parameter mail_owner: user postfix has same user ID as _postfix
- How to specify which editor is used when editing posts with WP-CLI?
- WP changes siteurl, but some URLs then don’t work
- Install plugin on remote wordpress
- WP-CLI is unable to update password
- Make WordPress more like Jekyll (using wp-cli package?)
- Find latest/published version of post using wp-cli
- Wp-cli from a plugin?
- Is it possible to update a single page using WP-CLI?
- undefined function apache_request_headers()
- ignoring, hidding mu plugins when wp-cli is run
- Install WordPress using PHP
- How to install WordPress with Composer?
- WordPress CLI isn’t working while use WordPress development repository
- Remote Export DB w. WP-cli.phar Over SSH
- is it possible to use wp cli to export custom post types
- Why doesn’t “wp db cli” enable tab completion?
- ‘wp’ is not recognized as an internal or external command, operable program or batch file