Filter uncanny-learndash-groups

uo_users_menu_items

Filters the user menu items and CSV export button before they are displayed in the admin area.

add_filter( 'uo_users_menu_items', $callback, 10, 2 );

Description

Allows developers to modify the menu items displayed in the Uncanny Groups users table. This hook can be used to add, remove, or alter existing menu items, including the CSV and Excel export buttons. It fires after the default menu items are generated, providing a late-stage opportunity for customization.


Usage

add_filter( 'uo_users_menu_items', 'your_function_name', 10, 2 );

Parameters

$users_menu_items (mixed)
This parameter contains an array of menu items to be displayed in the users' table actions.
$csv_export_button (mixed)
This parameter contains an array of menu items that will be displayed in the user management section of the Uncanny Groups plugin.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to add a custom menu item to the Uncanny Groups user table actions.
 * This example adds a new button to trigger a custom user data export process.
 *
 * @param array $users_menu_items An array of existing menu items, typically HTML buttons.
 * @param array $export_data An associative array containing information about available export buttons and other features.
 *
 * @return array The modified array of user menu items.
 */
add_filter( 'uo_users_menu_items', 'my_custom_users_menu_items', 10, 2 );

function my_custom_users_menu_items( $users_menu_items, $export_data ) {
	// Check if our custom export button should be displayed.
	// In a real scenario, this might depend on user roles or specific group settings.
	$should_display_custom_export = current_user_can( 'manage_options' );

	if ( $should_display_custom_export ) {
		// Add a new button to the menu items array.
		// This button could trigger a JavaScript function to initiate a custom export.
		$users_menu_items['custom_user_export'] = '<button class="uo-btn uo-left" id="group-management-custom-user-export" data-group-id="' . esc_attr( $export_data['group_id'] ?? '' ) . '">
											' . __( 'Custom User Export', 'my-text-domain' ) . '
										</button>';
	}

	// Always return the modified or original array of menu items.
	return $users_menu_items;
}

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/templates/frontend-uo_groups/users-table-actions.php:388

}
						if ( $excel_export_button ) {
							$users_menu_items['excel_export_button'] = '<button class="ulgm-modal-link uo-btn uo-left" id="group-management-users-export-excel">
											' . __( 'Export Excel', 'uncanny-learndash-groups' ) . '
										</button>';
						}

						$users_menu_items = apply_filters(
							'uo_users_menu_items',
							$users_menu_items,
							array(
								'csv_export_button'      => $csv_export_button,
								'excel_export_button'    => $excel_export_button,
								'populate_management_features' => $populate_management_features,
								'add_user_button'        => $add_user_button,

Scroll to Top