I want to trigger an API call to another system every single time when a new user register (in real time). Therefore, I opened the wp-login.php and I was able to locate the register form but I'm not sure where to call a php function with the API call.

I tried adding a JavaScript API call but the MIME type is not allowed and therefore blocked.

Where do I have to inject the API call in php?

Thank you

UPDATE: Here is the code from my hook I created:

Plugin Name: HM Reigster Form
Version: 0.1
Author: JP Wallhorn 
Description: Customization of WordPress Register Form. API Call to create user in Salesforce.
add_action('user_register', 'salesforceAPICall');
function salesforceAPICall ( $user_id ) {
    $user_info = get_userdata($user_id);
    $username = $user_info->user_login;
    $mail = $user_info->user_email; 
    $postfields = array(
            'FirstName' => $user_info->first_name,
            'LastName'  => $user_info->last_name,
            'Email'     => $user_info->user_email,
            'Wordpress_ID__c' => $user_info->user_login
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, '<URL>');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    // Edit: prior variable $postFields should be $postfields;
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // On dev server only!
    $result = curl_exec($ch);
    echo curl_error($ch);
    echo json_encode($result);
    echo json_encode($ch);
  • You shoud use WordPress hooks, in this case user_register action may the hook you need. – cybmeta May 17 '17 at 7:08
  • Hey, I've actually done that but for some reason, the API call doesn't work. I just added my code to the post above. Maybe you can take a look at it @cybmeta – jP_ May 18 '17 at 1:05
  • Well, your question was "Where do I have to inject the API call in php?", anyway, what do you mean with "the API call doesn't work"? As it is a third party API, we don't know nothing it and we can not test it; better if you ask to the devs who develop that API. – cybmeta May 18 '17 at 5:05
  • Sorry true that. I forgot I was doing additional research me awhile :) let me check. Currently it's actually a server error, I'll keep you posted. – jP_ May 18 '17 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.