Support

Home Forums WP User Integration Event registration = wordpress registration?

Event registration = wordpress registration?

Posted: May 6, 2014 at 12:46 pm


Jeremy

May 6, 2014 at 12:46 pm

If I join an event should I be automatically added to wordpress users or is there something I need to do for this to happen?

Thx


Lorenzo Orlando Caum

  • Support Staff

May 6, 2014 at 1:32 pm

Hi Jeremy,

Event Espresso 3 does not do this on its own but you can do this by using some code like this:

https://gist.github.com/Apina/5576163

We recommend adding this to a site specific plugin: http://ottopress.com/2011/creating-a-site-specific-snippets-plugin/

Cheers


Lorenzo


Jeremy

May 6, 2014 at 6:54 pm

Hi Lorenzo

Thanks for the information. I did as suggested. Do I add this to the plugins for the site or is there a plugins folder within espresso?

The reason I ask is that I added to contents/plugins for wordpress and now no emails are sent out for the user at all. They are recorded on espresso users but not on wordpress. Also I do not get a user activate email at all.

Any ideas what I can do next?

Thanks


Jeremy

May 6, 2014 at 7:50 pm

I have redone the file and now get the message:

Fatal error: Cannot redeclare espresso_create_wp_user() (previously declared in /home/hearts/public_html/wp-content/plugins/heart-tours/heart-tours.php:7) in /home/hearts/public_html/wp-content/plugins/heart-tours/heart-tours.php on line 29

For your information I have added code below:

<pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”><?php
/*
Plugin Name: Site Plugin for heart-tours.com
Description: Site specific code changes for heart-tours
*/
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 roleadd_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
} $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
}
?>


Dean

May 7, 2014 at 1:27 am

Hi,

The snippet should go into either the themes functions.php or to wp-content/uploads/espresso/custom_functions.php (you may need to make this file).

Here is an alternative version of the above, please read the notes on it https://gist.github.com/Apina/9596012

The fatal error you have received is because you have the function in two places and the can be only one.

The support post ‘Event registration = wordpress registration?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso