Zapier Extension Filter Hooks

Overview

Version 1.0.4 of the Zapier extension introduces two new filter hooks, allowing you to conditionally control when data is sent to the Zapier webhook based on form field values.

1. um_zapier_webhook_before_post_data

This filter hook allows you to modify the data before it's sent to the Zapier webhook. You can use this to check for specific field values and prevent the webhook from being triggered if those values don’t meet your conditions.

Example Usage:

Below is an example of how to prevent the webhook from posting data if the dropdown value for the "gender" field is not set to "Male."

add_filter( 'um_zapier_webhook_before_post_data', 'um_zapier_02132025_webhook_before_post_data' ); 
function um_zapier_02132025_webhook_before_post_data( $field_data ) {
    // Check if the gender field value is not Male
    if( isset( $field_data['gender'] ) && 'Male' != $field_data['gender'] ) {
        // Stop posting data to the Zapier webhook
        add_filter( 'um_zapier_send_api_post', '__return_false' ); 
    }  
    return $field_data;
}

Explanation:

  • um_zapier_webhook_before_post_data: This hook is applied just before posting data to the Zapier webhook. It allows you to conditionally modify the data or prevent the webhook from being triggered.
  • The custom function checks if the gender field exists and if it is set to "Male." If the condition is not met, it adds a um_zapier_send_api_post filter to stop the webhook from posting data.

2.um_zapier_send_api_post

This filter hook controls whether the API request to Zapier is sent. By default, it returns true, allowing the request to be made. However, you can return false to prevent the API request from being triggered.

Example Usage:

Below is an example of how to use this hook to prevent sending the API request based on a custom field value:

add_filter( 'um_zapier_send_api_post', 'um_zapier_custom_field_check', 10, 2 );
function um_zapier_custom_field_check( $send, $field_data ) {
    // Only send the API request if the "marketing_optin" field is "yes"
    if ( isset( $field_data['marketing_optin'] ) && 'yes' != $field_data['marketing_optin'] ) {
        // Prevent sending the API request
        return false;
    }
    return $send;
}<br>

Explanation:

  • um_zapier_send_api_post: This hook allows you to control whether the API request is sent to Zapier. By default, it allows the request to be made, but you can return false to stop the request from being triggered.
  • The function checks the value of the marketing_optin field. If it is not "yes," it returnsfalse, preventing the request from being sent.

Summary of Filter Hooks:

  1. um_zapier_webhook_before_post_data: Modify or stop the data from being sent to Zapier based on field values.
  2. um_zapier_send_api_post: Control whether the API request to Zapier is sent, preventing it based on custom conditions.