Get user profile from auth0 to create wordpress user with the good profile

Hi,

I’m newbie with auth0.
Is there a way to get the user profile from auth0 when login to select the good profile in wordpress for the user creation.
Standard users which logged will have the subscriber profile in wp and journalists users will have a specific profile in WP : Journalist :slight_smile:
TIA for help
Francis

Hi @francis,

Welcome to the Auth0 Community!

The recommended way of retrieving the Auth0 user profile on user creation in Wordpress is using actions and filters to run custom code at specific points during runtime, more specifically the auth0_create_user_data filter. It allows you to intercept the data packet right before it hits the WordPress database to create the account. You can check out our documentation on how to Extend Login by Auth0 WordPress Plugin, which provides more details, potentially other options of achieving this as well.

When you use this filter, the $userinfo object contains either the Custom Claim or the metadata that you will have to inject via an Auth0 Action. You can check out this articles - Add Roles and Permissions to the ID Token Using Actions or Adding Custom Claims to Tokens. You then inject the corresponding WordPress role into the $user_data array.

An important distinction here would be that auth0_create_user_data only runs when the user doesn’t exist in WP yet, when auth0_user_login runs every time. If you want roles to stay synchronized (e.g., if a journalist’s contract ends and you demote them in Auth0), you should use the login hook instead.

I will also recommend checking out this community post, since it pinpoints to the same subject - Set a users WordPress role and provides useful Wordpress documentation as well - How to change a user’s role?

Thank you for posting your questions and if you have further inquiries on the matter please reach out to us, as we are more than glad to assist!
Kind regards,
Remus

1 Like

Thanks to you and the resources you have pointed me to, I have a better idea of where I need to go.

Thank you very much.

1 Like

Hi @francis,

You are more than welcome anytime!

Make sure you have a great one!
Remus