Last active
February 16, 2016 16:58
-
-
Save sethshoultes/5574217 to your computer and use it in GitHub Desktop.
This action creates a WordPress user when someone registers for your an event. It uses the email address of the registrant to create the user name and the password is randomly generated. Add this function and action to your theme/functions.php file. More info in the comments below.
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 | |
add_action('action_hook_espresso_save_attendee_data','espresso_create_wp_user', 10, 1); | |
function espresso_create_wp_user($attendee_data) { | |
if( username_exists( $attendee_data['email'] ) == NULL ) { | |
global $org_options; | |
// Generate the password and create the user | |
$password = wp_generate_password( 12, false ); | |
$user_id = wp_create_user( $attendee_data['email'], $password, $attendee_data['email'] ); | |
// Set the users details | |
//Additional fields can be found here: http://codex.wordpress.org/Function_Reference/wp_update_user | |
wp_update_user( | |
array( | |
'ID' => $user_id, | |
'nickname' => $attendee_data['fname'] . ' ' . $attendee_data['lname'], | |
'display_name' => $attendee_data['fname'] . ' ' . $attendee_data['lname'], | |
'first_name' => $attendee_data['fname'], | |
'last_name' => $attendee_data['lname'], | |
'description' => __('Registered via event registration form.', 'event_espresso'), | |
) | |
); | |
// Set the role | |
$user = new WP_User( $user_id ); | |
$user->set_role( 'subscriber' ); | |
// Email the user | |
wp_mail( $attendee_data['email'], 'Welcome to ' . $org_options['organization'], 'Your Username: ' .$attendee_data['email']. ' Your Password: ' . $password ); | |
} // end if | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Fellow event exspresso developers is there a update for this function in EE4 or does anybody know of any hooks that are available for to add this code to in EE4