ulgm_group_leader_columns
Filters the columns displayed in the group leader list, allowing customization of the table headers and their order.
add_filter( 'ulgm_group_leader_columns', $callback, 10, 1 );
Description
Filters the array of columns displayed in the Uncanny Groups leader table. Developers can add, remove, or modify column definitions to customize the leader table's appearance and data. The $array parameter is an array of column objects.
Usage
add_filter( 'ulgm_group_leader_columns', 'your_function_name', 10, 1 );
Parameters
-
$array(mixed) - This parameter holds an array of column definitions for the group leader table, with each definition being an object specifying data source, target, title, and type.
Return Value
The filtered value.
Examples
/**
* Add a custom column to the group leader table.
*
* This function demonstrates how to use the 'ulgm_group_leader_columns'
* filter to add a new column to the group leader management interface.
* In this example, we'll add a column for the user's registration date.
*
* @param array $columns An array of existing column definitions.
* @return array The modified array of column definitions.
*/
add_filter( 'ulgm_group_leader_columns', 'my_custom_group_leader_columns', 10, 1 );
function my_custom_group_leader_columns( $columns ) {
// Check if the columns array is valid and not empty
if ( ! is_array( $columns ) || empty( $columns ) ) {
return $columns;
}
// Find the position for our new column.
// For demonstration, let's add it after the 'email' column.
$insert_after_key = false;
foreach ( $columns as $key => $column ) {
if ( isset( $column->data ) && 'email' === $column->data ) {
$insert_after_key = $key;
break;
}
}
// Define the new column's properties
$new_column = (object) array(
'data' => 'registration_date',
'title' => __( 'Registration Date', 'your-text-domain' ), // Use a unique text domain
'type' => 'date', // You might need a custom renderer or a standard type
);
// If we found a place to insert, add the new column there.
// Otherwise, append it to the end.
if ( false !== $insert_after_key ) {
// Split the array and insert the new column
$beginning_part = array_slice( $columns, 0, $insert_after_key + 1 );
$end_part = array_slice( $columns, $insert_after_key + 1 );
$columns = array_merge( $beginning_part, array( $new_column ), $end_part );
} else {
$columns[] = $new_column;
}
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:1468
public static function set_group_leader_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 = apply_filters( 'ulgm_group_leader_columns', $array );
// Loop thru array and assign
// targets based on the position
if ( $array ) {
$j = 0;
foreach ( $array as $k => $v ) {
$v->targets = $j;
++$j;
}
}
return $array;
}