brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp shell opens an interactive PHP prompt inside your WordPress site

WordPress
~/tips/tip-wordpress-wp-shell-interactive-php

wp shell

Starts an interactive PHP console with WordPress loaded, to try functions and inspect data.

Testing a WordPress function usually means editing a file and reloading a page. wp shell lets you type it and see the answer.

wp shell
wp> get_bloginfo( 'name' );
wp> get_option( 'blogdescription' );

The handbook describes it as an interactive PHP console in a loaded WordPress environment. You can evaluate statements and expressions, and use WordPress functions, classes and globals as you would in a plugin. Its own example is get_bloginfo( 'name' );, which returns the site name.

Type restart to reload the shell in a new PHP process, so edited code is picked up. That needs pcntl_exec(). Without it the shell restarts in the same process, which resets variables but does not reload PHP files.

--basic forces WP-CLI’s built-in REPL even when Boris or PsySH is installed. --quiet suppresses the printed return value, so an assignment prints nothing.

The caveat is that this is the real site. Reading options or posts is harmless, but calls like update_option() or wp_delete_post() change the live database immediately, with no confirmation. Try the read-only function first, and take a backup with wp db export before anything that writes. The handbook also marks --watch and --hook as not yet in a stable release, so skip them unless you use the nightly build.

Further reading: WP-CLI: wp shell

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link