ld_group_email_users_args
Filters the arguments passed to the `wp_mail()` function for sending group emails.
add_filter( 'ld_group_email_users_args', $callback, 10, 1 );
Description
Fires before sending emails to group members via the REST API. Developers can use this filter to modify or add arguments passed to the email sending function, customizing recipients or email content. Allows fine-grained control over the email dispatch process.
Usage
add_filter( 'ld_group_email_users_args', 'your_function_name', 10, 1 );
Parameters
-
$mail_args(mixed) - This parameter contains an array of arguments that will be used to construct and send an email to users within a LearnDash group.
Return Value
The filtered value.
Examples
/**
* Example of how to modify the arguments for sending emails to group users.
*
* This filter allows you to alter the arguments used when sending emails
* to users within a LearnDash group. For instance, you might want to
* add custom headers or modify the subject line.
*
* @param array $mail_args The current mail arguments.
* @return array The modified mail arguments.
*/
function my_learndash_group_email_args( $mail_args ) {
// Example: Add a custom header to the email.
if ( ! isset( $mail_args['headers'] ) ) {
$mail_args['headers'] = array();
}
$mail_args['headers'][] = 'X-My-Custom-Header: SomeValue';
// Example: Modify the subject line.
if ( isset( $mail_args['subject'] ) ) {
$mail_args['subject'] = '[Custom Prefix] ' . $mail_args['subject'];
}
return $mail_args;
}
add_filter( 'ld_group_email_users_args', 'my_learndash_group_email_args', 10, 1 );
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
src/classes/helpers/rest-api-end-points.php:829
wp_send_json_error(
array(
'message' => esc_html__( 'No users found in the group matching the criteria.', 'uncanny-learndash-groups' ),
)
);
}
$mail_args = apply_filters( 'ld_group_email_users_args', $mail_args );
if ( empty( $mail_args ) ) {
wp_send_json_error(
array(
'message' => __( 'Mail args empty. Unexpected condition from filter: ld_group_email_users_args.', 'uncanny-learndash-groups' ),
)
);
}