Posts in the developer's cookbook category describe topics that require technical knowledge. Be warned and use the techniques at your own risk. Unless you are an experienced developer, you are strongly advised to ask a professional for support.
Contact Form 7 has an integration module with Brevo (formerly Sendinblue) that manages a contact database derived from contact form submissions. To add a contact data to the database, Contact Form 7 sends a request to the Brevo API. This recipe describes how you can customize the request parameters using the wpcf7_sendinblue_contact_parameters
filter hook.
Brevo’s API reference lists eight different parameters for a request to create a contact, but in most cases, you will only need to specify four of them, namely: email
, attributes
, listIds
, and updateEnabled
.
The email
parameter specifies the email address of the contact. By default, Contact Form 7 sets this parameter to the email address input by the form submitter.
The attributes
parameter is the set of contact attributes and their values. Note that an attribute name must be in capital letters and correspond to an attribute name defined in your Brevo account (Contacts > Settings > Contact attributes).
The listIds
parameter is an array of integer values that specifies the IDs of the lists to which the created contact is to belong.
The updateEnabled
parameter specifies whether to update the existing contact data that shares the same email. By default, this value is set to false, meaning if the same email is already in the database, Brevo will not update the contact and the request will simply be ignored.
The following is a coding example modifying those parameters:
add_filter(
'wpcf7_sendinblue_contact_parameters',
function ( $params ) {
// Email
$params['email'] = 'testing@example.com';
// Attributes
// Don't forget to cast to an object.
$params['attributes'] = (object) array(
'LASTNAME' => 'Test',
'FIRSTNAME' => 'Tester',
'TEST_BOOL' => true,
);
// List IDs
$params['listIds'] = array( 5, 2 );
// Update existing contact
$params['updateEnabled'] = true;
// See https://developers.brevo.com/reference/createcontact
// for the full list of available parameters
return $params;
},
10, 1
);