Description
The wpforms_entry_email_atts
filter allows modifying email notification attributes programmatically before sending notifications. This is particularly useful when managing complex notification logic that would be impractical to configure through the form builder.
Parameters
- (array) The email notification attributes including subject, message, and other settings.
- $fields
- (array) Form fields data and values.
- $entry
- (array) Entry data and metadata.
- $form_data
- (array) Processed form settings/data, prepared to be used later.
- $notification_id
- (array) The ID of the current notification being processed.
This filter provides allows to modify email notification attributes programmatically before they are sent. This is especially valuable when dealing with complex conditional notification logic based on form field values, such as country-specific notifications or multiple recipient scenarios.
You can access and modify the email subject using $email['subject']
. This allows for programmatic customization of the subject line based on your specific requirements.
Example
/**
* Customize email notification attributes.
*
* @link https://wpforms.com/developers/wpforms_entry_email_atts
*
* @param array $email Email notification settings.
* @param array $fields Form fields data.
* @param array $entry Entry data.
* @param array $form_data Form data and settings.
* @param int $notification_id Notification ID.
*
* @return array
*/
function wpf_custom_email_notification( $email, $fields, $entry, $form_data, $notification_id ) {
// Add custom logic here to modify email attributes based on form fields
// Example: Modify subject, recipients, sender info based on country selection
return $email;
}
add_filter( 'wpforms_entry_email_atts', 'wpf_custom_email_notification', 10, 5 );