Filter uncanny-learndash-groups

ulgm_maybe_send_redemption_email

Filters whether a redemption email should be sent, modifying the email subject and recipient.

add_filter( 'ulgm_maybe_send_redemption_email', $callback, 10, 2 );

Description

Filters whether to send a group redemption email. Developers can modify the email subject and body, or prevent the email from sending by returning false. This hook fires after email content is generated and before the email is sent.


Usage

add_filter( 'ulgm_maybe_send_redemption_email', 'your_function_name', 10, 2 );

Parameters

$to (mixed)
This parameter, a boolean, controls whether the redemption email should be sent.
$subject (mixed)
The `$to` parameter is used to specify the recipient(s) of the redemption email.

Return Value

The filtered value.


Examples

/**
 * Conditionally prevent sending a redemption email based on user role.
 *
 * This filter allows administrators to prevent redemption emails from being sent
 * to users with specific roles (e.g., administrators themselves).
 *
 * @param bool   $send_email The original decision to send the email (true by default).
 * @param string $to         The recipient's email address.
 * @param string $subject    The email subject.
 *
 * @return bool True to send the email, false to prevent sending.
 */
add_filter( 'ulgm_maybe_send_redemption_email', function( $send_email, $to, $subject ) {
	// Get the current user object.
	$current_user = wp_get_current_user();

	// Define roles that should not receive redemption emails.
	$restricted_roles = array( 'administrator', 'editor' );

	// Check if the current user has any of the restricted roles.
	if ( user_can( $current_user->ID, 'manage_options' ) ) {
		// If the user can manage options, they likely have administrator privileges.
		// Prevent sending the email in this case.
		return false;
	}

	// If no restrictions apply, return the original decision.
	return $send_email;
}, 10, 3 );

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/group-management/class-group-management-helpers.php:1677

$subject = apply_filters( 'ulgm_redemption_email_subject', $redemption_template_subject, $user_data, $group_id );
			$body    = apply_filters( 'ulgm_redemption_email_body', $redemption_template_body, $user_data, $group_id );

			if ( ! class_exists( 'WP_Better_Emails' ) || ( false === preg_match( '/<DOCTYPE/', $body ) && false === preg_match( '/<head>/', $body ) ) ) {
				$body = wpautop( $body );
			}

			$send_email = apply_filters( 'ulgm_maybe_send_redemption_email', true, $to, $subject );
			do_action( 'ulgm_redemption_email_sent', $user_data, $group_id );

			if ( $send_email && 'yes' === get_option( 'ulgm_send_code_redemption_email', 'yes' ) ) {
				$redemption_email = SharedFunctions::wp_mail( $to, $subject, $body, self::get_headers() );

				//If the mail is successful let a a fake user and group meta
				if ( is_wp_error( $redemption_email ) ) {


Scroll to Top