Hooks for the emails a Form block sends, the data it posts to a webhook, and the email marketing services it connects to. To add your own action or service, see Registering form actions and Registering form integrations.
Jump to
- Emails
- Webhooks
- Email marketing services
Emails
generateblocks_form_email_use_html
GB Pro — since GenerateBlocks 2.6.
The generateblocks_form_email_use_html filter chooses whether the notification email sent to the site uses the built-in HTML template or plain text.
Parameters: $send_html (bool), $sanitized_data (array, the sanitized form data), $form_settings (array, the form settings), $context (array with post_id and page_url). Default: true.
add_filter( 'generateblocks_form_email_use_html', '__return_false' );
Related: generateblocks_form_email_args Guide: Forms
generateblocks_form_email_args
GB Pro — since GenerateBlocks 2.6.
The generateblocks_form_email_args filter changes the notification email before it is sent. The values you return are sanitized afterwards.
Parameters: $email_args (array with to (array of addresses), subject, body and headers (array of header strings)), $sanitized_data (array), $form_settings (array), $context (array). Default: the recipients, subject, body and headers built from the form’s settings.
add_filter( 'generateblocks_form_email_args', function( $email_args, $sanitized_data, $form_settings, $context ) {
$email_args['headers'][] = 'Bcc: records@example.com';
return $email_args;
}, 10, 4 );
Related: generateblocks_form_confirmation_email_args Guide: Forms
generateblocks_form_confirmation_email_args
GB Pro — since GenerateBlocks 2.6.
The generateblocks_form_confirmation_email_args filter changes the confirmation email sent to the person who submitted the form, before it is sent.
Parameters: $email_args (array with to (string, the recipient’s address), subject, body and headers), $sanitized_data (array), $form_settings (array), $context (array). Default: the address, subject, body and headers built from the form’s settings.
add_filter( 'generateblocks_form_confirmation_email_args', function( $email_args, $sanitized_data, $form_settings, $context ) {
$email_args['subject'] .= ' - Example Co.';
return $email_args;
}, 10, 4 );
Related: generateblocks_form_email_args Guide: Forms
Webhooks
generateblocks_form_webhook_payload
GB Pro — since GenerateBlocks 2.6.
The generateblocks_form_webhook_payload filter changes the data a form posts to its webhook. Field values are sent at the top level, for receivers that only map top-level keys, and are repeated under fields. If a field name matches one of the other keys, the field value wins the top-level slot.
Parameters: $payload (array), $sanitized_data (array, the full sanitized data with labels and types), $form_settings (array), $context (array). Default: form_name, fields, page_url and timestamp (an ISO 8601 UTC date), followed by every field value.
add_filter( 'generateblocks_form_webhook_payload', function( $payload, $sanitized_data, $form_settings, $context ) {
$payload['source'] = 'my-site';
return $payload;
}, 10, 4 );
Related: generateblocks_form_after_process Guide: Forms
Email marketing services
generateblocks_form_register_email_integrations
GB Pro — since GenerateBlocks 2.6.
The generateblocks_form_register_email_integrations action fires when the form system starts, before the built-in actions are set up. Use it to supply the API key for a built-in service, so editors don’t have to enter it in the form editor. Call generateblocks_pro_set_email_integration( $service, $api_key ) inside it.
Parameters: none. Default: —
The service IDs are mailchimp, activecampaign, brevo, convertkit and mailerlite. Some services also accept their key as a constant, for example GENERATEBLOCKS_PRO_MAILERLITE_API_KEY.
add_action( 'generateblocks_form_register_email_integrations', function() {
generateblocks_pro_set_email_integration( 'mailchimp', 'your-api-key' );
} );
Related: generateblocks_form_register_integrations Guide: Forms
generateblocks_form_register_integrations
GB Pro — since GenerateBlocks 2.6.
The generateblocks_form_register_integrations action fires after the built-in integrations are registered. Use it to add a service to the form editor by calling generateblocks_pro_register_form_integration( $args ). It runs after the built-ins, so registering an ID that already exists replaces the built-in definition for that request.
Parameters: none. Default: —
add_action( 'generateblocks_form_register_integrations', function() {
generateblocks_pro_register_form_integration( [
'id' => 'my-crm',
'label' => __( 'My CRM', 'my-plugin' ),
'type' => 'email',
] );
} );
Related: Registering form integrations, generateblocks_form_register_email_integrations Guide: Forms