Filter
uncanny-automator
automator_drip_subscriber_fields
Filters subscriber fields before saving to Drip, allowing modification of data passed to the integration.
add_filter( 'automator_drip_subscriber_fields', $callback, 10, 3 );
Description
Filters the subscriber data array before it's sent to Drip for subscriber creation. This hook allows developers to modify, add, or remove fields from the subscriber object, control how data is mapped, and ensure Drip receives the exact information required. It fires just before the Drip API call is made.
Usage
add_filter( 'automator_drip_subscriber_fields', 'your_function_name', 10, 3 );
Parameters
-
$subscriber(mixed) - This parameter is an array that will be populated with subscriber data, often initialized as an empty array.
-
$email(mixed) - This parameter holds an array that will be populated with the Drip subscriber data.
-
$fields(mixed) - This parameter holds the email address of the subscriber being created or updated in Drip.
Return Value
The filtered value.
Examples
<?php
/**
* Add a custom field to Drip subscribers based on a user meta value.
*
* This example demonstrates how to intercept the fields being sent to Drip
* and add or modify a subscriber field based on additional user data.
*
* @param array $subscriber The current subscriber data array.
* @param string $email The email address of the subscriber.
* @param array $fields The original fields array passed to the action.
* @return array The modified subscriber data array.
*/
add_filter( 'automator_drip_subscriber_fields', function ( $subscriber, $email, $fields ) {
// Check if the 'user_id' is available in the subscriber data.
// This assumes the user ID is passed in the $subscriber array by the plugin.
if ( ! empty( $subscriber['user_id'] ) ) {
$user_id = $subscriber['user_id'];
$user = get_userdata( $user_id );
// If the user exists, get their first name and add it as a custom Drip field.
if ( $user ) {
$first_name = $user->first_name;
// Add 'first_name' as a custom field to the Drip subscriber data.
// Drip typically uses keys that match their custom field names.
// Adjust 'first_name' if your Drip custom field has a different API name.
if ( ! empty( $first_name ) ) {
$subscriber['first_name'] = $first_name;
}
}
}
// You could also conditionally remove fields or modify existing ones.
// For instance, if you wanted to remove a field that's always sent by default:
// if ( isset( $subscriber['some_default_field'] ) ) {
// unset( $subscriber['some_default_field'] );
// }
return $subscriber;
}, 10, 3 );
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/drip/actions/drip-create-subscriber.php:208
private function build_subscriber( $email, $fields ) {
$subscriber = array();
$default_fields = self::default_fields();
foreach ( $fields as $field ) {
if ( empty( $field['FIELD_NAME'] ) || ! isset( $field['FIELD_VALUE'] ) ) {
continue;
}
$name = $field['FIELD_NAME'];
$value = $field['FIELD_VALUE'];
if ( ! in_array( $name, $default_fields, true ) ) {
$subscriber['custom_fields'][ $name ] = $value;
continue;
}
// Type cast known fields.
switch ( $name ) {
case 'sms_consent':
case 'prospect':
$value = filter_var( $value, FILTER_VALIDATE_BOOLEAN );
break;
case 'tags':
case 'remove_tags':
$value = array_map( 'trim', explode( ',', $value ) );
break;
case 'base_lead_score':
$value = intval( $value );
break;
}
$subscriber[ $name ] = $value;
}
$subscriber['email'] = $email;
return apply_filters( 'automator_drip_subscriber_fields', $subscriber, $email, $fields );
}