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 user application-password create gives a WordPress REST client its own key

WordPress
~/tips/tip-wordpress-application-password-rest

wp user application-password create anna backup-script --porcelain

Creates a revocable password for one script or app to call the REST API.

A script that talks to the REST API should never get your real login. Application passwords exist for that.

wp user application-password create anna backup-script --porcelain

This creates an application password named backup-script for user anna. --porcelain prints only the password. The script then uses basic auth with the user name and that password:

curl -u 'anna:abcd efgh ijkl mnop qrst uvwx' https://example.com/wp-json/wp/v2/users/me

The spaces are only there for readability; WordPress strips them before it checks the password. The script gets the rights of that user, so pick a user with a role that fits the job. wp user application-password list anna shows all of them with their last use, and wp user application-password delete revokes one without touching anything else. That is the big advantage over sharing a normal password: one leaked key, one delete.

I think the next rule is a good one: WordPress only offers application passwords over HTTPS, or when the environment type is local. On a plain HTTP site the feature is simply missing, because basic auth over HTTP sends the password in the clear. Store the password like any other secret, in an environment variable or a password manager, not in the script.

Further reading: wp user application-password create, REST API authentication

More WordPress tips define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size wp server --host=127.0.0.1 --port=8080 All WordPress tips (85) All topics

Link