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 core is-installed lets a script check for WordPress by exit code

WordPress
~/tips/tip-wordpress-core-is-installed-script

if ! wp core is-installed 2>/dev/null; then

Returns success when WordPress is installed, so a deploy script can branch on it.

Some WP-CLI commands are made for scripts, not for people. This one prints nothing at all.

wp core is-installed answers with its exit code: 0 when WordPress is installed in the database, non-zero when it is not. That makes it a clean condition for a setup script:

if ! wp core is-installed 2>/dev/null; then
  wp core install --url=https://example.com --title="Example" \
    --admin_user=admin [email protected] --skip-email
fi

The 2>/dev/null keeps error text out of the output when the database is still empty. I like this pattern for container setups, where the same entrypoint runs on the first start and every start after it. The install only happens once.

On multisite, add --network to check that the install is a network.

What it checks is the database, not the files. A folder with WordPress files and a wp-config.php pointing at an empty database counts as not installed. And when the database cannot be reached at all, you also get a non-zero exit. So in a script that matters, check the connection first with wp db check, or a failed connection could trigger a second install attempt.

Further reading: wp core is-installed, wp core install

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