Description
The wsf_action_email_to filter allows you to modify the To array of email addresses when sending emails using the Send Email action.
Usage
add_filter( 'wsf_action_email_to', 'my_hook_function', 10, 4 );
Parameters
Example
// Callback function for the wsf_action_email_to filter hook
function my_hook_function( $to, $form, $submit, $action ) {
// ID of form this filter hook applies to
$form_id = 123;
// ID of field
$field_id = 123;
// Check form ID
if( $form_id != $form->id ) { return $to; }
// Build meta key containing the field value
$meta_key = sprintf( 'field_%u', $field_id );
// Get field value (Will be an array of values for a select, checkbox or radio field)
$values = wsf_submit_get_value( $submit, $meta_key );
// Check field value
if( empty( $values ) || !is_array( $values ) ) { return $to; }
// Field value to email address lookup table (Build this data using your own code)
$to_lookups = array(
'Sales' => 'Sales <sales@mysite.com>',
'Support' => 'Support <support@mysite.com>'
);
// Return array
$to_array = array();
// Process values
foreach( $values as $value ) {
// Check if lookup exists
if( isset( $to_lookups[$value] ) ) {
// If it does exist, add this email address to the return array
$to_array[] = $to_lookups[$value];
}
}
// Return value
return count( $to_array ) ? $to_array : $to;
}
// Add a callback function for the wsf_action_email_to filter hook
add_filter( 'wsf_action_email_to', 'my_hook_function', 10, 4 );
Source File
This hook can be found in:<plugin root>/includes/actions/class-ws-form-action-email.php