Filter uncanny-learndash-groups

ulgm_group_leader_data

Filters the data associated with a group leader before it's displayed or used.

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

Description

Filters the data array used to display group leader information. Developers can modify this data, for example, to add custom columns or adjust existing values before they are rendered in the group leader management interface.


Usage

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

Parameters

$group_data (mixed)
This parameter contains an array of data related to the group, including enrolled leader information, checkboxes, management features, and remaining seat information.

Return Value

The filtered value.


Examples

/**
 * Example of modifying the group leader data before it's localized for the frontend.
 *
 * This filter allows you to dynamically alter the data passed to the JavaScript
 * for displaying group leader information. For instance, you might want to
 * add an extra flag or modify existing data based on certain conditions.
 *
 * @param array $group_data The original group leader data array.
 * @return array The modified group leader data array.
 */
add_filter( 'ulgm_group_leader_data', function( $group_data ) {

    // Check if there's any leader data to process.
    if ( isset( $group_data['enrolled_leader_data'] ) && ! empty( $group_data['enrolled_leader_data'] ) ) {

        // Example: Add a custom property to each leader, indicating if they have a specific role.
        // In a real scenario, you'd likely fetch user roles or meta data.
        foreach ( $group_data['enrolled_leader_data'] as $leader_id => &$leader ) {
            // Simulate checking for a specific role or meta.
            // Replace this with actual logic to determine the role.
            $leader['is_senior_leader'] = ( rand( 0, 1 ) === 1 ); // Randomly assign for demonstration
        }
    }

    // Example: Modify the number of remaining seats if it's below a certain threshold.
    if ( isset( $group_data['groupSeatsLeft'] ) && $group_data['groupSeatsLeft'] < 5 ) {
        $group_data['low_seat_warning'] = true;
        $group_data['seat_warning_message'] = sprintf(
            __( 'Only %d seats remaining in this group!', 'your-text-domain' ),
            $group_data['groupSeatsLeft']
        );
    }

    return $group_data;

}, 10, 1 );

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

'enrolled_leader_data'         => self::$ulgm_group_leaders_data_dt,
				'check_all'                    => self::table_checkbox( 'all' ),
				'populate_management_features' => wp_json_encode( self::$populate_management_features ),
				'groupSeatsLeft'               => ulgm()->group_management->seat->remaining_seats( self::$ulgm_current_managed_group_id ),
			);

			$group_data = apply_filters_deprecated( 'ulgmGroupLeaderData', array( $group_data ), '4.2.1', 'ulgm_group_leader_data' );
			$group_data = apply_filters( 'ulgm_group_leader_data', $group_data );

			wp_localize_script( 'ulgm-frontend', 'ulgmGroupLeaderData', $group_data );

			wp_localize_script( 'ulgm-frontend', 'ulgmGroupManagementLocalized', self::$ulgm_management_shortcode );

			wp_enqueue_script( 'ulgm-frontend' );

Scroll to Top