Filter
uncanny-automator
automator_ontraport_upsert_fields
Filters the fields used when upserting contacts or leads to Ontraport, allowing customization before data submission.
add_filter( 'automator_ontraport_upsert_fields', $callback, 10, 2 );
Description
Allows developers to modify the fields sent to Ontraport for contact upserts. This filter hook is applied just before data is sent to Ontraport, giving you the chance to add, remove, or alter any field values based on your needs. Use it to customize the data structure or map custom fields.
Usage
add_filter( 'automator_ontraport_upsert_fields', 'your_function_name', 10, 2 );
Parameters
-
$fields(mixed) - This parameter contains an array of available fields for the Ontraport upsert contact action.
-
$this(mixed) - This parameter contains an array of fields that can be used to upsert a contact in Ontraport.
Return Value
The filtered value.
Examples
add_filter( 'automator_ontraport_upsert_fields', 'my_custom_ontraport_upsert_fields', 10, 2 );
/**
* Customizes the fields available for Ontraport contact upserts.
*
* This function demonstrates how to add a new custom field or modify
* existing ones in the array of fields used when upserting contacts
* to Ontraport via Uncanny Automator.
*
* @param array $fields An array of field definitions for Ontraport upserts.
* @param object $this The instance of the action class performing the upsert.
* @return array The modified array of field definitions.
*/
function my_custom_ontraport_upsert_fields( $fields, $this ) {
// Example: Add a custom field for 'Lead Source' if it's not already present.
$lead_source_field_exists = false;
foreach ( $fields as $field ) {
if ( isset( $field['key'] ) && 'lead_source' === $field['key'] ) {
$lead_source_field_exists = true;
break;
}
}
if ( ! $lead_source_field_exists ) {
$fields[] = array(
'key' => 'lead_source',
'label' => __( 'Lead Source', 'uncanny-automator' ),
'description' => __( 'Enter the source of this lead (e.g., Website, Referral, Paid Ad).', 'uncanny-automator' ),
'input_type' => 'text',
'required' => false,
);
}
// Example: Modify an existing field, e.g., make 'Status' required.
foreach ( $fields as &$field ) {
if ( isset( $field['key'] ) && 'status' === $field['key'] ) {
$field['required'] = true;
$field['description'] = __( 'The contact's status in Ontraport (now required).', 'uncanny-automator' );
break;
}
}
unset( $field ); // Unset the reference after the loop.
// Example: Remove a field if it's not needed for a specific scenario.
// For instance, if you never want to upsert the LinkedIn link directly.
$fields = array_filter( $fields, function( $field ) {
return ! ( isset( $field['key'] ) && 'linkedin_link' === $field['key'] );
} );
// Re-index the array to ensure sequential keys if fields were removed.
return array_values( $fields );
}
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/ontraport/actions/ontraport-upsert-contact.php:53
public function options() {
$fields = array();
$fields[] = $this->helpers->get_email_field( $this->get_action_meta() );
$fields = array_merge( $fields, $this->get_contact_field_options() );
$fields[] = $this->get_status_field( false );
return apply_filters( 'automator_ontraport_upsert_fields', $fields, $this );
}