Filter uncanny-learndash-groups

ulgm_welcome_emails_get_real_group_id

Filters the actual group ID used for welcome emails, allowing modification before it's processed.

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

Description

Filters the actual group ID for welcome emails. This hook allows developers to override the automatically determined parent group ID for a given group. It fires after the parent group is identified but before it's returned. Use this to manually set a different parent group for welcome email targeting.


Usage

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

Parameters

$actual_group_id (mixed)
This parameter contains the actual group ID that will be returned after potential filtering.
$group_id (mixed)
This parameter is the actual group ID found by traversing the post ancestors, which will be returned if no other filter modifies it.

Return Value

The filtered value.


Examples

add_filter( 'ulgm_welcome_emails_get_real_group_id', 'my_custom_group_id_filter', 10, 2 );

/**
 * Example filter to modify the real group ID for welcome emails.
 *
 * This function intercepts the calculated 'actual_group_id' and applies a custom logic.
 * For instance, if the 'actual_group_id' is a specific parent group, we might want to
 * redirect it to a different, more general group for welcome email targeting.
 *
 * @param mixed $actual_group_id The calculated group ID.
 * @param mixed $group_id        The original group ID passed to the filter.
 * @return mixed The potentially modified group ID.
 */
function my_custom_group_id_filter( $actual_group_id, $group_id ) {
    // Let's say we want to ensure that if the actual group ID is group 123,
    // we instead use group 456 for sending welcome emails.
    if ( 123 === $actual_group_id ) {
        // Log this modification for debugging purposes (optional).
        error_log( "ULGM Welcome Emails: Redirecting welcome emails for original group ID {$group_id} from actual group ID {$actual_group_id} to group ID 456." );
        return 456; // Return the new group ID.
    }

    // If no specific modification is needed, return the original calculated ID.
    return $actual_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:28

public static function get_real_group_id( $group_id ) {
		if ( false === apply_filters( 'ulgm_welcome_emails_check_real_group_id', false, $group_id ) ) {
			return $group_id;
		}
		$ancestors       = get_post_ancestors( $group_id );
		$actual_group_id = array_pop( $ancestors );

		return apply_filters( 'ulgm_welcome_emails_get_real_group_id', $actual_group_id, $group_id );
	}


Scroll to Top