ld_group_email_users_after
Fires after a group email is sent to users, allowing modification of email arguments or return values.
add_action( 'ld_group_email_users_after', $callback, 10, 2 );
Description
Fires after a group email is sent to users within LearnDash. Developers can use this hook to perform custom actions following email delivery, such as logging delivery status, updating user meta, or triggering further notifications. `$mail_args` contains email parameters, and `$mail_ret` indicates the success or failure of the `wp_mail` function.
Usage
add_action( 'ld_group_email_users_after', 'your_function_name', 10, 2 );
Parameters
-
$mail_args(mixed) - This parameter contains an array of arguments used for sending the email.
-
$mail_ret(mixed) - This parameter contains an array of arguments that were used to send the email, including the recipient, subject, and message.
Examples
add_action(
'ld_group_email_users_after',
function ( $mail_args, $mail_ret ) {
// Example: Log the email sending status for a specific group.
// This could be useful for debugging or auditing purposes.
// Check if we're dealing with a specific group ID we want to monitor.
// Replace 123 with the actual group ID you're interested in.
if ( isset( $mail_args['group_id'] ) && $mail_args['group_id'] === 123 ) {
$recipient_email = isset( $mail_args['to'] ) ? $mail_args['to'] : 'unknown';
$subject = isset( $mail_args['subject'] ) ? $mail_args['subject'] : 'No Subject';
if ( $mail_ret ) {
// Log successful email
error_log(
sprintf(
'LD Group Email Success: Group ID %d, To: %s, Subject: "%s"',
$mail_args['group_id'],
$recipient_email,
$subject
)
);
} else {
// Log failed email
error_log(
sprintf(
'LD Group Email Failed: Group ID %d, To: %s, Subject: "%s"',
$mail_args['group_id'],
$recipient_email,
$subject
),
E_USER_WARNING // Use a warning level for failures
);
}
}
},
10, // Priority
2 // Accepted args count ($mail_args, $mail_ret)
);
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:869
$mail_ret = SharedFunctions::wp_mail(
$email_address,
$mail_args_subject,
$mail_args_message,
Group_Management_Helpers::get_headers( true, $group_leader_details, $group_id )
);
$mail_args['to'] = $email_address;
do_action( 'ld_group_email_users_after', $mail_args, $mail_ret );
unset( $backup_emails[ $k ] );
if ( ! $mail_ret ) {
$mail_errors[] = $email_address;
} else {
$mail_success[] = $email_address;