Filter uncanny-learndash-groups

ulgm_rest_api_get_user_course_data

Filters the user course data retrieved from the REST API before it's returned.

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

Description

Fires after user course data is retrieved for the REST API. Developers can modify the returned data array, which includes user course details, testing status, and function calls. This hook is useful for customizing the data sent back to the client or for debugging purposes before the JSON response is generated.


Usage

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

Parameters

$data (mixed)
This parameter holds the data array that will be sent back as a JSON response, containing information about user course data and reporting settings.
$_POST (mixed)
This parameter contains the data that will be returned by the REST API endpoint.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the data returned by the ulgm_rest_api_get_user_course_data hook.
 * This example adds an 'additional_info' key to the data and conditionally modifies
 * 'reload' based on a value from the $_POST data.
 */
add_filter( 'ulgm_rest_api_get_user_course_data', function( $data, $_POST ) {

	// Add some custom information to the data.
	$data['additional_info'] = 'This is custom data added by the filter.';

	// Conditionally change the 'reload' value based on a POST parameter.
	// For example, if a 'force_refresh' parameter is set to 'true' in the POST request,
	// we might want to force a reload of the report data.
	if ( isset( $_POST['force_refresh'] ) && $_POST['force_refresh'] === 'true' ) {
		$data['reload'] = true;
	}

	// You could also modify or add to 'function_vars' if needed.
	// For instance, if you wanted to pass an additional variable to 'populateReportTable'.
	// $data['function_vars']['custom_setting'] = 'some_value';

	// Always return the modified data.
	return $data;

}, 10, 2 ); // 10 is the priority, 2 is the number of arguments accepted by the callback function.

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/reports/group-reports-interface.php:636

$data['testing']       = false;
		$data['reload']        = false;
		$data['call_function'] = 'populateReportTable';
		$data['function_vars'] = array(
			'user_course_data' => $user_course_data,
		);

		$data = apply_filters( 'ulgm_rest_api_get_user_course_data', $data, $_POST );
		wp_send_json_success( $data );
	}

	/**
	 * @param $course_id
	 * @param $group_id
	 * @param false $user_id

Scroll to Top