I am having trouble accessing the user_metadata
information in WordPress. I am currently using the Auth0 plugin.
I have a bare-bones application and I would like to see the user’s first name and last name in the application. I added the two additional fields to additionalSignUpFields
configuration option as shown below.
{
"additionalSignUpFields": [
{
"name": "first_name",
"placeholder": "Please enter your first name"
},
{
"name": "last_name",
"placeholder": "Please enter your last name"
}
]
}
This works great. New users can add the additional metadata to their profiles via the signup form. However, I am having trouble accessing the user’s first name and last name within the WordPress application.
I stumbled upon Custom fields with wordpress? - #2 by kimcodes and it is mentioned that this data should be attached to the wp_auth0_obj
in WordPress.
Here is a code snippet I am using to access the wp_auth0_obj
.
<?php
$user_id = get_current_user_id();
$key = 'wp_auth0_obj';
$single = true;
$auth0_user = get_user_meta( $user_id, $key, $single );
print_r($auth0_user);
?>
This results in printing a similar object to this (values have been changed and removed for privacy):
{
"created_at": "2021-02-19T19:10:36.216Z",
"email": "test@test.com",
"email_verified": true,
"identities": [
{
"user_id": "",
"provider": "auth0",
"connection": "",
"isSocial": false
}
],
"name": "test@test.com",
"nickname": "",
"picture": "",
"updated_at": "2021-02-22T21:54:25.377Z",
"user_id": "",
"last_ip": "",
"last_login": "2021-02-22T21:54:25.377Z",
"logins_count": 14,
"sub": ""
}
I do not see a user_metadata
property object.
Should I be seeing it?
How can I get access to the user_metadata
in WordPress?
I appreciate your help!