Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MailChimp User Sync: Filter user that is used by the webhook. Create new user when no user is found.
<?php
add_filter( 'mailchimp_sync_webhook_user', function( $user, $data ) {
// have user already? use that.
if( $user instanceof \WP_User ) {
return $user;
}
// no user yet, let's create one.
$user_id = wp_create_user( $data['email'], wp_generate_password(), $data['email'] );
// send notification to user
wp_new_user_notification( $user_id );
// return complete user object
return get_userdata( $user_id );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.