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 eval runs a line of PHP inside a fully loaded wordpress

WordPress
~/tips/tip-wordpress-eval-php-loaded-wordpress

wp eval 'echo get_option( "blogname" ), PHP_EOL;'

Executes a snippet of PHP with WordPress loaded, without writing a plugin or a template.

For a quick check I do not want to create a plugin or a test page.

wp eval 'echo get_option( "blogname" ), PHP_EOL;'
wp eval-file check.php

wp eval loads WordPress and then executes the PHP you give it, so every core function and loaded plugin is available. Use single quotes around the code in the shell and double quotes inside it. wp eval-file does the same for a file, and extra arguments reach it in $args. The code runs with full rights and without a user, so it can change or delete data. Run it on a copy first and take a database export before anything that writes.

Further reading: WP-CLI: wp eval

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