Skip to content

Instantly share code, notes, and snippets.


evansims/example.php Secret

Last active Dec 3, 2020
What would you like to do?
Auth0 WordPress example
This example hooks the 'auth0_create_user_data' action and 'wpa0_user_created' filter
to demonstrate how you could attach custom data to a user at user creation time.
// auth0_create_user_data is a filter that allows you to alter user data BEFORE the user is created
add_action( 'auth0_create_user_data', 'example_auth0_create_user_data', 10, 2 );
// wpa0_user_created is an action triggered AFTER a user is created.
add_action( 'wpa0_user_created', 'example_auth0_user_created', 10, 5 );
function example_auth0_create_user_data( array $user_data, $userinfo ) {
$user_data represents the user data parsed from the Auth0 profile.
$userinfo is the Auth0 user profile itself.
You must return an array representing what should be passed to wp_insert_user().
An example of this can be found at
$user_data['description'] = 'I created this account with Auth0!';
return $user_data;
function example_auth0_user_created( $user_id, $email, $password, $f_name, $l_name ) {
$user_id is the internal WordPress ID for the created user.
$email is the email address of the created user.
$password is the password of the created user.
$f_name is the first name of the created user.
$l_name is the last name of the created user.
An example of this can be found at
$user = get_user_by('id', $user_id);
$userDisplayName = get_the_author_meta('display_name', $user_id) ?? $f_name;
wp_mail($email, "Thanks for registering, ${userDisplayName}!", 'We just wanted to welcome you to your new WordPress account! Have a nice day!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment