need some help connecting wordpress registration form to infusionsoft

64 views Asked by At

I'm new to all of this and I've tried searching myself but didn't find what I needed. I need to connect the default WordPress registration form to infusionsoft. So every time a new member registers, I get their email address in my contact list at infusionsoft. Hope I explained it correctly. Feel free to edit my question.

1

There are 1 answers

0
merctraider On

There's a lot you have to set up, so I'll just skim over the things you need to do before the solution. I've added some links that you can refer to as you go.

What you'll first need is Infusionsoft's PHP SDK. If you're unsure of how to set it up, refer to this: https://blog.terresquall.com/2021/03/using-keaps-aka-infusionsoft-php-sdk-2021/

Create the Authentication bit as a menu page in your Wordpress Admin dashboard.

After you've figured out the authentication, you can save the generated access token to your Infusionsoft API as an option within WordPress. Use register_setting()and get_option() to save your Access Token for the API calls in your plugin/theme.

After that, you need to use the user_register hook, which will be called after the user registers, to make the API call that will ultimately send over the registration details to infusionsoft:

add_action( 'user_register', 'user_to_infusionsoft', 10, 1 );

function user_to_infusionsoft($user_id){
    //Include your infusionsoft PHP SDK path if you haven't already
    
    $infusionsoft = $infusionsoft = new \Infusionsoft\Infusionsoft(array(
    'clientId'     => 'Your API key goes here',
    'clientSecret' => 'Your API secret goes here',
    'redirectUri'  => 'http://yourwebsite.com/authentication.php',
    ));
    
    //Retrieve the access token that you generated and saved from the options
    $token = get_option('infusionsoft_token');
    $infusionsoft->setToken(unserialize($token));
    $user_info = get_userdata($user_id);

//Set up the email in the format to be used by the API
    $user_email =  new \stdClass;
    $user_email->field = 'EMAIL1';
    $user_email->email = $user_info->user_email; 

    $contact = ['given_name' => $user_info->first_name, 'family_name' => $user_info->last_name, 'email_addresses' => [$user_email]];

    $infusionsoft->contacts()->create($contact);

    

}