Filter uncanny-learndash-groups

ulgm_mail_body

Filters the email body content before it is sent, allowing for customization of message content.

add_filter( 'ulgm_mail_body', $callback, 10, 1 );

Description

Filters the email body content before it's sent. Developers can modify the HTML or plain text of the email body, allowing for dynamic content injection or customization of outgoing notifications. This hook runs after shortcodes are processed.


Usage

add_filter( 'ulgm_mail_body', 'your_function_name', 10, 1 );

Parameters

$body (mixed)
The `$body` parameter contains the HTML or plain text content of the email that will be sent.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the email body for the 'ulgm_mail_body' hook.
 * This function will add a custom footer to the email body.
 *
 * @param string $body The original email body content.
 * @return string The modified email body content.
 */
add_filter( 'ulgm_mail_body', 'my_custom_email_body_footer', 10, 1 );

function my_custom_email_body_footer( $body ) {
    // Ensure we're dealing with a string before appending.
    if ( ! is_string( $body ) ) {
        // If it's not a string, try to cast it or return as is.
        // For robustness, we might log this unexpected type.
        $body = (string) $body;
    }

    // Define the custom footer text.
    $footer_text = "nn---n";
    $footer_text .= "This is a custom footer added by My Plugin.n";
    $footer_text .= "Please do not reply to this automated email.";

    // Append the custom footer to the email body.
    $body .= $footer_text;

    // Return the modified email body.
    return $body;
}

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/shared-functions.php:917

public static function wp_mail( $to, $subject, $body, $headers = array(), $attachment = array() ) {
		$body       = do_shortcode( $body );
		$subject    = do_shortcode( $subject );
		$to         = apply_filters( 'ulgm_mail_to', $to );
		$subject    = apply_filters( 'ulgm_mail_subject', html_entity_decode( $subject ) );
		$body       = apply_filters( 'ulgm_mail_body', html_entity_decode( $body ) );
		$headers    = apply_filters( 'ulgm_mail_headers', $headers );
		$attachment = apply_filters( 'ulgm_mail_attachment', $attachment );

		return wp_mail( $to, $subject, $body, $headers, $attachment );
	}


Scroll to Top