Auth0 Home Blog Docs

Set a users WordPress role

Where can I set a users WordPress role from within auth0? Currently they are setup as subscribers. If it needs to be do with code, can someone help with an example?

Hi @shae … Auth0 does not do anything to manage WordPress roles at all. When a new account is created, the plugin uses the default WordPress role to assign to a user. You can have WordPress key off of user_metadata or app_metadata but that logic would be custom, we don’t support that within the plugin currently.

1 Like

When you say have WordPress key off of user_metadata or app_metadata Where would that need to setup. I am looking to be able to set the wordpress role from within the Auth0 dashboard.

Best bet in this case is to use app_metadata so the user can’t modify that themselves. That’s on the User Details page in Auth0:

Then, in WordPress, you’ll want to use one of the post-login hooks to look for that data when they return from a successful authentication. Best bet is probably auth0_user_login:

In that $userinfo parameter you should get the app_metadata, like so:

   // ...
   // ..

You can use the add/remove_role methods for WP_User to adjust as needed. There’s a good example below. Just make sure you’re using sane defaults if the role is not valid or empty. In other words, check the incoming role for existence in WP before changing:

Hope that helps!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.