ulgm_enrolled_group_leader_data
Filters the data for enrolled group leaders, allowing modification before it's displayed or used by the core plugin.
add_filter( 'ulgm_enrolled_group_leader_data', $callback, 10, 1 );
Description
Filters the data array for enrolled group leaders. Developers can modify this array to alter the group leader information before it's used by the plugin. This hook fires after group leader data is retrieved and processed.
Usage
add_filter( 'ulgm_enrolled_group_leader_data', 'your_function_name', 10, 1 );
Parameters
-
$ulgm_group_leaders_data_dt(mixed) - This parameter contains the group leader data that is being filtered.
Return Value
The filtered value.
Examples
/**
* Example of using the ulgm_enrolled_group_leader_data filter.
* This example adds a 'status' column to the group leader data,
* indicating if the group leader is currently active.
*/
add_filter( 'ulgm_enrolled_group_leader_data', 'my_custom_group_leader_data', 10, 1 );
/**
* Custom function to modify group leader data.
*
* @param array $ulgm_group_leaders_data_dt The array of group leader data.
* @return array The modified array of group leader data.
*/
function my_custom_group_leader_data( $ulgm_group_leaders_data_dt ) {
// Ensure we have data to work with.
if ( empty( $ulgm_group_leaders_data_dt ) ) {
return $ulgm_group_leaders_data_dt;
}
// Get the current managed group ID (assuming it's available globally or passed differently).
// In a real scenario, you'd need to access this context. For this example,
// we'll simulate fetching it or assume it's available.
// Let's assume a function `get_current_managed_group_id()` exists or use a global.
// Replace with actual method to get current group ID if needed.
$current_group_id = isset( $GLOBALS['ulgm_current_managed_group_id'] ) ? $GLOBALS['ulgm_current_managed_group_id'] : 0;
// Fetch all users associated with the group, not just administrators,
// to check their 'active' status within the group context if that's relevant.
// This is a hypothetical scenario for demonstration.
// In a real plugin, you might have a way to check group membership or status.
// For this example, we'll assume a function `get_users_in_group_with_status()` exists.
// Replace with actual logic to fetch user status related to the group.
$group_member_statuses = array();
if ( $current_group_id ) {
// Hypothetical function that returns an array like: [user_id => 'active'/'inactive']
$group_member_statuses = get_users_in_group_with_status( $current_group_id );
}
// Iterate through each group leader's data.
foreach ( $ulgm_group_leaders_data_dt as $key => &$leader_data ) {
// Add a new field 'status' to the group leader data.
// We check if the user is in the group and what their status is.
$user_id = $leader_data['id'];
$status = 'Unknown'; // Default status
if ( ! empty( $group_member_statuses[ $user_id ] ) ) {
$status = ucfirst( $group_member_statuses[ $user_id ] ); // e.g., 'Active' or 'Inactive'
} else {
// If the user is not found in the group_member_statuses,
// we might infer their status differently or mark it as unknown.
// For simplicity, we'll default to 'Unknown' if not explicitly found.
}
$leader_data['status'] = $status;
// Example: If a leader is marked as 'Inactive', maybe we want to visually
// distinguish them or remove them from certain lists.
// For this example, we'll just add the status.
}
unset( $leader_data ); // Unset the reference to avoid unintended modifications.
return $ulgm_group_leaders_data_dt;
}
/**
* Hypothetical function to simulate fetching user statuses within a group.
* In a real plugin, this would interact with WordPress user meta, custom tables,
* or other group management logic.
*
* @param int $group_id The ID of the group.
* @return array An associative array of user IDs and their statuses.
*/
function get_users_in_group_with_status( $group_id ) {
// This is a placeholder. Replace with actual logic to fetch user statuses.
// For demonstration, let's assume some users are active and others inactive.
$users_statuses = array();
// Simulate fetching users and their statuses.
// In a real scenario, this could be based on a custom field,
// a dedicated group membership status in a meta table, etc.
$all_users_in_group = get_users( array( 'role__in' => array( 'administrator', 'editor', 'subscriber' ) ) ); // Get some users as an example
if ( $all_users_in_group ) {
foreach ( $all_users_in_group as $user ) {
// Simulate status for users who are leaders in the current group context
// (assuming the group ID is relevant to their status)
if ( $user->ID % 2 == 0 ) { // Example: even IDs are active
$users_statuses[ $user->ID ] = 'active';
} else { // Example: odd IDs are inactive
$users_statuses[ $user->ID ] = 'inactive';
}
}
}
return $users_statuses;
}
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:1119
public static function set_group_leaders_data() {
if ( ! empty( self::$ulgm_group_leaders_data_dt ) ) {
return;
}
$groups_user_object = LearndashFunctionOverrides::learndash_get_groups_administrators( self::$ulgm_current_managed_group_id, true );
if ( $groups_user_object ) {
foreach ( $groups_user_object as $user ) {
$f = get_user_meta( $user->ID, 'first_name', true );
$l = get_user_meta( $user->ID, 'last_name', true );
$email = $user->user_email;
self::$ulgm_group_leaders_data_dt[] = (object) array(
'check' => ( $user->ID !== get_current_user_id() ) ? self::table_checkbox( $user->ID ) : '',
'first_name' => $f,
'last_name' => $l,
'email' => '<a href="mailto:' . $email . '" class="edit_assignment groups-email-mailto-link">' . $email . '</a>',
'id' => $user->ID,
);
}
}
self::$ulgm_group_leaders_data_dt = apply_filters( 'ulgm_enrolled_group_leader_data', self::$ulgm_group_leaders_data_dt );
}