Filter uncanny-learndash-groups

ulgm_group_management_invited_user_status

Filters the displayed status for a user invited to a group, allowing customization of the "Not Enrolled" display.

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

Description

Filters the status display for invited users within the Uncanny LearnDash Groups management interface. Developers can modify the HTML output for the user's enrollment status. This hook is applied when displaying the list of invited users, allowing customization of how their enrollment status, such as "Not Enrolled," is presented.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of using the 'ulgm_group_management_invited_user_status' filter.
 *
 * This function modifies the displayed status for invited users in the group management interface.
 * For example, it could change the status to "Pending Acceptance" if the user hasn't accepted yet.
 *
 * @param string $status_html The default HTML for the status (e.g., "Not Enrolled").
 * @param WP_User $user       The user object for the invited user.
 * @param int    $group_id    The ID of the group.
 * @return string             The modified HTML for the user's status.
 */
add_filter( 'ulgm_group_management_invited_user_status', function( $status_html, $user, $group_id ) {
	// In a real-world scenario, you would check if the user has actually accepted the invitation.
	// For demonstration, let's assume a user with a specific role is considered "Pending".
	$user_roles = (array) $user->roles;

	// Example: If the user has a role of 'pending_group_invitation', change the status.
	if ( in_array( 'pending_group_invitation', $user_roles ) ) {
		return '<div class="status status-pending" data-status="pending">' . __( 'Pending Acceptance', 'uncanny-learndash-groups' ) . '</div>';
	}

	// You could also check if the user has any LearnDash enrollments related to this group.
	// For instance, if they are invited but not enrolled in any courses within this group.
	// Example: Check if user is enrolled in any courses associated with the group.
	// (This would require more complex logic to fetch group courses and check user enrollment)

	// If no special conditions are met, return the original status HTML.
	return $status_html;
}, 10, 3 );

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:1077

$key   = $user->code;

			self::$ulgm_enrolled_users_data_dt[] = (object) array(
				'check'      => self::table_checkbox( $key ),
				'first_name' => $f,
				'last_name'  => $l,
				'email'      => '<a href="mailto:' . $email . '" class="edit_assignment groups-email-mailto-link">' . $email . '</a>',
				'status'     => apply_filters( 'ulgm_group_management_invited_user_status', '<div class="status status-not-enrolled" data-status="not-enrolled">' . __( 'Not Enrolled', 'uncanny-learndash-groups' ) . '</div>', $user, $group_id ),
				'status_id'  => apply_filters( 'ulgm_group_management_invited_user_status_id', 'not-enrolled', $user, $group_id ),
				'key'        => $key,
				'id'         => null,
			);
		}

		self::$ulgm_enrolled_users_data_dt = apply_filters_deprecated( 'ulgm_enrolled_user_data', array( self::$ulgm_enrolled_users_data_dt ), '4.2.1', 'ulgm_group_management_enrolled_user_data' );


Scroll to Top