Filter uncanny-learndash-groups

ulgm_course_parent_enrolled_hierarchy_disable

Filters whether to disable the parent enrolled course hierarchy. Use this to control display of nested enrolled courses.

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

Description

Filters whether to disable child group hierarchy data when a course is enrolled to the parent group. Return `true` to disable, `false` to enable. This hook fires before child group hierarchy data is potentially hidden, allowing developers to override the default behavior based on custom logic.


Usage

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

Parameters

$group_id (mixed)
This parameter is a boolean value that determines whether the hierarchy for child group data should be disabled.

Return Value

The filtered value.


Examples

/**
 * Conditionally disable hierarchy for child groups when the parent group is enrolled.
 *
 * This filter allows developers to override the default behavior of disabling
 * child group data when a course is enrolled to the parent group. For instance,
 * you might want to always show child group data regardless of parent enrollment
 * for specific reporting needs.
 *
 * @param bool   $disable_hierarchy_for_children Whether to disable hierarchy. Defaults to true.
 * @param int    $group_id The ID of the current group being processed.
 * @return bool The new value for $disable_hierarchy_for_children.
 */
add_filter( 'ulgm_course_parent_enrolled_hierarchy_disable', function( $disable_hierarchy_for_children, $group_id ) {

	// Example: If this is a specific group (e.g., group ID 15) where you *always*
	// want to show child group data, regardless of parent enrollment, then return false.
	// Otherwise, keep the default behavior (which is to disable if parent is enrolled).
	if ( $group_id === 15 ) {
		return false;
	}

	// For all other groups, respect the original filter value (which is 'true' by default
	// if the parent group is enrolled).
	return $disable_hierarchy_for_children;

}, 10, 2 ); // 10 is the priority, 2 is the number of arguments accepted by the callback function.

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/reports/group-reports-interface.php:669

'search'  => $search,
		);

		// Check if course is enrolled to the parent group.
		$parent_enrolled = get_post_meta( $course_id, "learndash_group_enrolled_{$group_id}", true );
		// Disable child group data if parent group is enrolled.
		if ( $parent_enrolled ) {
			$args['hierarchy-disable'] = apply_filters( 'ulgm_course_parent_enrolled_hierarchy_disable', true, $group_id );
		}
		$groups_user_object = LearndashFunctionOverrides::ulgm_get_group_users( $group_id, $args, $user_id );

		if ( empty( $groups_user_object ) ) {
			$data['message'] = __( 'There are no users in this group', 'uncanny-learndash-groups' );
			$data['error']   = 'no-group-users';

Scroll to Top