# Set a users WordPress role

**URL:** <https://community.auth0.com/t/set-a-users-wordpress-role/21391>\
**Category:** Get Help\
**Tags:** wordpress\
**Created:** [February 16, 2019, 2:22pm UTC](https://community.auth0.com/t/set-a-users-wordpress-role/21391 "2019-02-16T14:22:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shae](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shae/32/11121_2.png) [@shae](https://community.auth0.com/u/shae)\
**Post date:** [February 16, 2019, 2:22pm UTC](https://community.auth0.com/t/set-a-users-wordpress-role/21391/1 "2019-02-16T14:22:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![josh.cunningham](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josh.cunningham/32/16289_2.png) [@josh.cunningham](https://community.auth0.com/u/josh.cunningham)\
**Post date:** [February 18, 2019, 9:09pm UTC](https://community.auth0.com/t/set-a-users-wordpress-role/21391/2 "2019-02-18T21:09:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shae](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shae/32/11121_2.png) [@shae](https://community.auth0.com/u/shae)\
**Post date:** [February 18, 2019, 11:53pm UTC](https://community.auth0.com/t/set-a-users-wordpress-role/21391/3 "2019-02-18T23:53:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![josh.cunningham](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josh.cunningham/32/16289_2.png) [@josh.cunningham](https://community.auth0.com/u/josh.cunningham)\
**Post date:** [February 19, 2019, 12:52am UTC](https://community.auth0.com/t/set-a-users-wordpress-role/21391/4 "2019-02-19T00:52:24Z")

</div>

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:

 ![23](https://global.discourse-cdn.com/auth0/original/2X/e/e042da2038453290f70fc51df364757049c92435.png)

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`:

> **[Extend Login by Auth0 WordPress Plugin](https://auth0.com/docs/customize/integrations/cms/wordpress-plugin/extend-login-by-auth0)**
>
> Learn how to extend the Login by Auth0 WordPress Plugin with hooks, filters, and functions.

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

```json
{  
   "email_verified":true,
   "email":"josh.cunningham@auth0.com",
   // ...
   "user_metadata":{},
   "app_metadata":{  
      "wordpress_role":"editor"
   },
   // ..
   "sub":"auth0|1234567890"
}

```

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:

> <https://wordpress.stackexchange.com/questions/4725/how-to-change-a-users-role/4727#4727>

Hope that helps!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 6, 2019, 12:52am UTC](https://community.auth0.com/t/set-a-users-wordpress-role/21391/5 "2019-03-06T00:52:28Z")

</div>

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