ulgm_user_welcome_email_subject
Filters the subject line of the user welcome email sent after group membership is confirmed.
add_filter( 'ulgm_user_welcome_email_subject', $callback, 10, 2 );
Description
Filters the subject line for the user welcome email. Developers can modify the default subject, which includes the site URL, or customize it based on the group ID for more targeted messaging. Allows for dynamic subject generation.
Usage
add_filter( 'ulgm_user_welcome_email_subject', 'your_function_name', 10, 2 );
Parameters
-
$string(mixed) - This parameter contains the welcome email subject line string.
-
$group_id(mixed) - This parameter contains the current subject line for the welcome email, which can be filtered by plugins.
Return Value
The filtered value.
Examples
add_filter( 'ulgm_user_welcome_email_subject', 'my_custom_welcome_email_subject', 10, 2 );
/**
* Customizes the subject line of the user welcome email for Uncanny Groups.
*
* This function allows you to dynamically change the welcome email subject based
* on the group the user is being added to, or provide a default override.
*
* @param string $subject The current subject line.
* @param int|null $group_id The ID of the group the user is being added to, or null.
* @return string The modified subject line.
*/
function my_custom_welcome_email_subject( $subject, $group_id = null ) {
// If a group ID is provided, check for group-specific overrides.
if ( $group_id ) {
// Get the group title for potential inclusion in the subject.
$group_title = get_the_title( $group_id );
// Example: Prepend the group title to the subject if it exists.
if ( ! empty( $group_title ) ) {
$subject = sprintf( '[%s] %s', esc_html( $group_title ), $subject );
}
// Example: Further customize based on specific group IDs.
if ( $group_id === 123 ) { // Replace 123 with an actual group ID.
$subject = __( 'Important Invitation to Join Our Exclusive Group', 'your-text-domain' );
} elseif ( $group_id === 456 ) { // Replace 456 with another group ID.
$subject = sprintf( __( 'Welcome aboard to %s!', 'your-text-domain' ), esc_html( $group_title ) );
}
}
// Example: Always append a site-specific suffix if not already present.
if ( strpos( $subject, '#SiteUrl' ) === false ) {
$site_url = network_home_url(); // Use network_home_url for multisite compatibility
$subject = str_replace( '#SiteUrl', esc_url( $site_url ), $subject );
}
return $subject;
}
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-variables.php:104
public static function user_welcome_email_subject( $group_id = null ) {
$string = get_option( 'ulgm_user_welcome_email_subject', false );
if ( ! $string ) {
$string = __( 'You have been added to #SiteUrl', 'uncanny-learndash-groups' );
}
if ( null !== $group_id ) {
$group_id = self::get_real_group_id( $group_id );
$new_user_email_override = get_post_meta( $group_id, 'ulgm_override_user_welcome_email', true );
if ( 'no' !== $new_user_email_override ) {
$new_user_email_subject = get_post_meta( $group_id, 'ulgm_override_user_welcome_email_subject', true );
if ( ! empty( $new_user_email_subject ) ) {
$string = $new_user_email_subject;
}
}
}
return apply_filters( 'ulgm_user_welcome_email_subject', wp_unslash( $string ), $group_id );
}