Filter
uncanny-automator-pro
automator_pro_bdb_send_email_to_all_group_members
Filters BuddyBoss group email headers before sending to all group members.
add_filter( 'automator_pro_bdb_send_email_to_all_group_members', $callback, 10, 2 );
Description
Filters the email headers before sending an email to all members of a BuddyBoss group. This hook allows developers to modify the headers, such as adding or changing Reply-To addresses or Content-Type, for the email sent by the "Send email to all members of group" action. The `$headers` array and the action's `$this` object are passed to the filter.
Usage
add_filter( 'automator_pro_bdb_send_email_to_all_group_members', 'your_function_name', 10, 2 );
Parameters
-
$headers(mixed) - This parameter contains the email headers for the message being sent.
-
$this(mixed) - This parameter contains an array or string representing the email headers to be sent.
Return Value
The filtered value.
Examples
add_filter(
'automator_pro_bdb_send_email_to_all_group_members',
function ( $headers, $automator_instance ) {
// Example: Add a custom header to all emails sent to BuddyBoss group members.
// This could be used for tracking or specific email client behaviors.
// Check if the automator instance is of the expected type to avoid errors
if ( $automator_instance instanceof Uncanny_Automator_ProIntegrationsBuddyBossActionsBDB_SendEmailToAllMembersOfGroup ) {
// Add a custom X-Mailer header.
$headers[] = 'X-Mailer: MyCustomWordPressMailer';
// You could also conditionally modify existing headers based on the automator instance.
// For example, if you wanted to change the Reply-To header only for a specific group.
// However, the provided context doesn't expose group ID directly here, so this is illustrative.
// $group_id = $automator_instance->get_group_id(); // Hypothetical method
// if ( $group_id === 123 ) {
// // Modify headers for group ID 123
// }
}
return $headers;
},
10, // Priority
2 // Accepted args: $headers, $this (which is the automator instance)
);
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
uncanny-automator-pro/src/integrations/buddyboss/actions/bdb-sendemailtoallmembersofgroup.php:237
protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
$group_id = $parsed['BDBGROUPS'] ?? '';
$from = $parsed['EMAILFROM'] ?? '';
$fromname = $parsed['EMAILFROMNAME'] ?? '';
$cc = $parsed['EMAILCC'] ?? '';
$bcc = $parsed['EMAILBCC'] ?? '';
$subject = $parsed['EMAILSUBJECT'] ?? '';
$body = $parsed['EMAILBODY'] ?? '';
$reply_to = $parsed['REPLYTO'] ?? '';
$members = array();
if ( function_exists( 'groups_get_group_members' ) ) {
$members = groups_get_group_members(
array(
'group_id' => absint( $group_id ),
'per_page' => 9999,
)
);
if ( ! empty( $members ) ) {
foreach ( $members['members'] as $member ) {
$headers[] = 'From: ' . $fromname . ' <' . $from . '>';
if ( ! empty( $cc ) ) {
$headers[] = 'Cc: ' . $cc;
}
if ( ! empty( $bcc ) ) {
$headers[] = 'Bcc: ' . $bcc;
}
if ( ! empty( $reply_to ) ) {
$headers[] = "Reply-To: $reply_to";
}
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$headers = apply_filters( 'automator_pro_bdb_send_email_to_all_group_members', $headers, $this );
// Send the email.
wp_mail( $member->user_email, $subject, $this->replace_newlines_in_body( $body ), $headers );
}
}
} else {
$action_data['complete_with_errors'] = true;
Automator()->complete->action( $user_id, $action_data, $recipe_id, esc_attr__( 'Buddyboss module is not active or not installed.', 'uncanny-automator-pro' ) );
return;
}
$this->hydrate_tokens(
array(
'GROUP_ID' => absint( $group_id ),
'GROUP_TITLE' => groups_get_group( absint( $group_id ) )->name,
)
);
Automator()->complete->action( $user_id, $action_data, $recipe_id );
}