ulgm_exiting_user_welcome_email_subject
Filters the subject line of the user welcome email sent after a user exits a group.
add_filter( 'ulgm_exiting_user_welcome_email_subject', $callback, 10, 2 );
Description
Filters the subject line for the welcome email sent to existing users joining a group. Developers can modify the default subject or add custom content. The hook receives the group ID for context.
Usage
add_filter( 'ulgm_exiting_user_welcome_email_subject', 'your_function_name', 10, 2 );
Parameters
-
$string(mixed) - This parameter is the subject line of the welcome email that will be sent to an existing user when they are added to a new group.
-
$group_id(mixed) - This parameter is the subject line of the welcome email, which can be customized via WordPress options.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the subject of the welcome email sent to existing users.
*
* This example appends the group name to the default subject line if a group ID is provided.
*
* @param string $subject The current email subject.
* @param int|null $group_id The ID of the group the user was added to.
*
* @return string The modified email subject.
*/
add_filter( 'ulgm_exiting_user_welcome_email_subject', function( $subject, $group_id ) {
// Check if we have a valid group ID and if it's not null.
if ( ! empty( $group_id ) && is_numeric( $group_id ) ) {
// Get the group name. We'll assume a function `get_group_name` exists for demonstration.
// In a real scenario, you would likely get this from the WordPress post object or a custom function.
$group = get_post( $group_id ); // Assuming group is a post type
if ( $group && 'group' === $group->post_type ) { // Adjust 'group' to your actual group post type
$group_name = $group->post_title;
// Append the group name to the existing subject.
$subject = sprintf( '%s - %s', $subject, $group_name );
}
}
return $subject;
}, 10, 2 ); // Priority 10, accepts 2 arguments ($subject, $group_id)
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:160
public static function exiting_user_welcome_email_subject( $group_id = null ) {
$string = get_option( 'ulgm_existing_user_welcome_email_subject', false );
if ( ! $string ) {
$string = __( 'You have been added to a new group on #SiteUrl', 'uncanny-learndash-groups' );
}
if ( null !== $group_id ) {
$group_id = self::get_real_group_id( $group_id );
$existing_user_email_override = get_post_meta( $group_id, 'ulgm_override_existing_user_welcome_email', true );
if ( 'no' !== $existing_user_email_override ) {
$existing_user_email_subject = get_post_meta( $group_id, 'ulgm_override_existing_user_welcome_email_subject', true );
if ( ! empty( $existing_user_email_subject ) ) {
$string = $existing_user_email_subject;
}
}
}
return apply_filters( 'ulgm_exiting_user_welcome_email_subject', wp_unslash( $string ), $group_id );
}