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 set-role changes what a WordPress account may do

WordPress
~/tips/tip-wordpress-user-set-role

wp user set-role anna author

Gives a user one new role and removes the roles the account had before.

A colleague who only writes doesn’t need to be an administrator. Changing that from the terminal takes one line.

wp user set-role anna author

The user can be a login, an email address or an ID. The role is a role key such as subscriber, contributor, author, editor or administrator, or a custom one from a plugin. Leave the role out and the user gets the site’s default role from Settings > General.

It really sets the role: WordPress removes every role the account had and gives it this one. Most sites only use one role per user, so that is what you’d expect. Some plugins, membership plugins for example, give users a second role on top. In that case set-role wipes the extra one too, and wp user add-role and wp user remove-role are the gentler tools.

Before you demote anyone, look at who has the most power:

wp user list --role=administrator --fields=ID,user_login

I would never demote the last administrator. You can fix it again from WP-CLI, but nobody can from the dashboard. On multisite, a super admin keeps network rights whatever the role on the site is.

Further reading: wp user set-role, WP_User::set_role()

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