ulgm_user_data_columns
Filters the user data columns displayed in the user list table, allowing customization of displayed columns.
add_filter( 'ulgm_user_data_columns', $callback, 10, 1 );
Description
Filter the array of column definitions for the enrolled users table. Developers can add, remove, or modify column data, targets, titles, and types to customize the displayed user information in Uncanny LearnDash Groups.
Usage
add_filter( 'ulgm_user_data_columns', 'your_function_name', 10, 1 );
Parameters
-
$array(mixed) - This parameter contains an array of column definitions for the user data table, where each definition is an object specifying properties like 'data', 'targets', 'title', and 'type'.
Return Value
The filtered value.
Examples
// Add a custom column to the enrolled users table to display the user's role.
add_filter( 'ulgm_user_data_columns', 'my_custom_ulgm_user_data_columns', 10, 1 );
/**
* Adds a custom 'Role' column to the enrolled users table.
*
* @param array $columns The existing array of columns.
* @return array The modified array of columns.
*/
function my_custom_ulgm_user_data_columns( $columns ) {
// Find the position where we want to insert our new column.
// For example, let's insert it after the 'email' column.
$insert_after_key = 'email';
$insert_position = -1;
foreach ( $columns as $key => $column ) {
if ( property_exists( $column, 'data' ) && $column->data === $insert_after_key ) {
$insert_position = $key + 1;
break;
}
}
// If the 'email' column wasn't found, just append it to the end.
if ( $insert_position === -1 ) {
$insert_position = count( $columns );
}
// Define the new custom column.
$custom_column = (object) array(
'data' => 'user_role',
'targets' => 'user_role',
'title' => __( 'Role', 'uncanny-learndash-groups' ),
);
// Insert the custom column at the determined position.
array_splice( $columns, $insert_position, 0, array( $custom_column ) );
// Note: The actual rendering of the 'user_role' data would likely require
// another filter or hook within the Uncanny Groups plugin to fetch and
// display the role for each user. This example only adds the column definition.
return $columns;
}
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:1437
public static function set_enrolled_users_columns() {
$array = array();
$array[] = (object) array(
'data' => 'first_name',
'targets' => 'first_name',
'title' => __( 'First name', 'uncanny-learndash-groups' ),
'type' => 'uo-groups-anchor',
);
$array[] = (object) array(
'data' => 'last_name',
'targets' => 'last_name',
'title' => __( 'Last name', 'uncanny-learndash-groups' ),
'type' => 'uo-groups-anchor',
);
$array[] = (object) array(
'data' => 'email',
'targets' => 'email',
'title' => __( 'Email', 'uncanny-learndash-groups' ),
);
$array[] = (object) array(
'data' => 'status',
'targets' => 'status',
'title' => __( 'Status', 'uncanny-learndash-groups' ),
);
$array[] = (object) array(
'data' => 'key',
'targets' => 'key',
'title' => __( 'Key', 'uncanny-learndash-groups' ),
'type' => 'uo-groups-anchor',
);
$array = apply_filters( 'ulgm_user_data_columns', $array );
return $array;
}