Filter uncanny-learndash-groups

ulgm_group_management_enrolled_user_status

Filters the enrollment status for a user within a LearnDash group, fired after course completions are processed.

add_filter( 'ulgm_group_management_enrolled_user_status', $callback, 10, 5 );

Description

Filters the status displayed for an enrolled user within group management. Developers can modify the status HTML, allowing for custom display logic based on user, group, or course completion data. This hook fires after initial status determination and before display.


Usage

add_filter( 'ulgm_group_management_enrolled_user_status', 'your_function_name', 10, 5 );

Parameters

$status (mixed)
This parameter holds the current status of the enrolled user, which can be filtered and modified by this hook.
$user (mixed)
This parameter holds the current enrollment status string for the user within the group.
$group_id (mixed)
This parameter contains information about the user whose enrollment status is being determined.
$learndash_group_enrolled_courses (mixed)
This parameter contains the ID of the group for which the user's enrollment status is being determined.
$completions_rearranged (mixed)
This parameter contains an array of the user's enrolled courses within the specified group, potentially rearranged for easier processing.

Return Value

The filtered value.


Examples

<?php

/**
 * Customizes the displayed status for enrolled users in Uncanny Groups.
 *
 * This filter allows you to modify the HTML output for the status of a user
 * within a specific group. For example, you might want to highlight users
 * who have completed a certain percentage of their courses or display a
 * custom message based on their progress.
 *
 * @param string $status                        The current HTML status string.
 * @param WP_User $user                         The WP_User object of the enrolled user.
 * @param int     $group_id                     The ID of the group the user is enrolled in.
 * @param array   $learndash_group_enrolled_courses An array of course IDs enrolled in the group.
 * @param array   $completions_rearranged       An array containing user course completion data.
 *
 * @return string The modified HTML status string.
 */
add_filter(
	'ulgm_group_management_enrolled_user_status',
	function ( $status, $user, $group_id, $learndash_group_enrolled_courses, $completions_rearranged ) {

		// Example: Highlight users who have completed all enrolled courses.
		$all_courses_completed = true;
		$total_enrolled_courses = count( $learndash_group_enrolled_courses );
		$completed_count = 0;

		if ( ! empty( $completions_rearranged[ $user->ID ] ) && is_array( $completions_rearranged[ $user->ID ] ) ) {
			foreach ( $learndash_group_enrolled_courses as $course_id ) {
				if ( isset( $completions_rearranged[ $user->ID ][ $course_id ] ) && $completions_rearranged[ $user->ID ][ $course_id ]['percentage'] === '100%' ) {
					$completed_count++;
				}
			}
		}

		// If there are no courses, we consider it not applicable.
		if ( $total_enrolled_courses === 0 ) {
			return '<div class="status status-not-started" data-status="not-started">' . __( 'No courses assigned', 'your-text-domain' ) . '</div>';
		}

		// If all courses are completed, change the status to 'Completed'.
		if ( $completed_count === $total_enrolled_courses && $total_enrolled_courses > 0 ) {
			$status = '<div class="status status-completed" data-status="completed">' . __( 'All Courses Completed', 'your-text-domain' ) . '</div>';
		} elseif ( $completed_count > 0 ) {
			// Otherwise, show a partial completion status.
			$status = '<div class="status status-in-progress" data-status="in-progress">' . sprintf( __( '%d/%d Courses Completed', 'your-text-domain' ), $completed_count, $total_enrolled_courses ) . '</div>';
		}

		return $status;
	},
	10,
	5 // This filter accepts 5 arguments.
);

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/group-management/group-management-interface.php:1041

}
				}

				if ( empty( $learndash_group_enrolled_courses ) ) {
					$status = '<div class="status status-not-started" data-status="not-started">' . apply_filters( 'ulgm_group_management_enrolled_user_na_status', __( 'N/A', 'uncanny-learndash-groups' ), $group_id ) . '</div>';
				}

				$status                              = apply_filters( 'ulgm_group_management_enrolled_user_status', $status, $user, $group_id, $learndash_group_enrolled_courses, $completions_rearranged );
				self::$ulgm_enrolled_users_data_dt[] = apply_filters(
					'ulgm_group_management_enrolled_user_info',
					(object) array(
						'check'      => self::table_checkbox( $user->ID ),
						'first_name' => self::user_edit_link( $f, 'first_name', $user->ID ),
						'last_name'  => self::user_edit_link( $l, 'last_name', $user->ID ),
						'email'      => '<a href="mailto:' . $email . '" class="edit_assignment groups-email-mailto-link">' . $email . '</a>',


Scroll to Top