Wordpress: trigger when User added

Hi.
Question: Can you please add to the Wordpress Pieces triggers when:
User Added

Then allow this to be used in any other Pieces?

Thnx.
LK

Hey @Lisa_Kristinardottir,

To set up a trigger for when a new user is added in WordPress, you can use the user_register action hook. Although it’s not as straightforward as using a WordPress piece, this workaround could serve your needs until the feature is available in Activepieces.

Here’s how to proceed:

  1. Edit your theme’s functions.php file.
  2. Hook into user_register: Add an action in your code to this hook.
  3. Define your webhook firing function: This function will send a POST request with the user’s data when a new user is registered.

Here’s a quick code snippet which might work:

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

function fire_ap_webhook($user_id) {
    $user = get_userdata($user_id);
    $user_email = $user->user_email
    $webhook_data = array(
        'user_id' => $user_id,
        'user_email' => $user_email,
        // Include additional user data as needed
        // Note: Ensure secure setup to protect personal data when using webhooks
    );
    $webhook_url = 'https://yourwebhook.url'; // Replace with your ActivePieces webhook trigger URL
    wp_remote_post($webhook_url, array(
        'method' => 'POST',
        'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
        'body' => json_encode($webhook_data),
        'data_format' => 'body',
    ));
}
2 Likes

You are a smart cookie @Dennis !

1 Like