-
-
Save evansims/c7116f83040af3e899213422489debc2 to your computer and use it in GitHub Desktop.
Auth0 WordPress example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
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 https://github.com/auth0/wp-auth0/blob/master/examples/auth0_create_user_data.php | |
*/ | |
$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 https://github.com/auth0/wp-auth0/blob/master/examples/wpa0_user_created.php | |
*/ | |
$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