Filter uncanny-learndash-groups

ulgm_quiz_report_user_data

Filters user data before displaying a quiz report, allowing modification of HTML variables and quiz/group details.

add_filter( 'ulgm_quiz_report_user_data', $callback, 10, 4 );

Description

This filter hook `ulgm_quiz_report_user_data` allows developers to modify the user data array used in group quiz reports. It fires just before the report data is generated, enabling customization of the user information displayed. Developers can alter or add to `$html_vars` based on `$quiz_ID`, `$group_ID`, and `$group_users`.


Usage

add_filter( 'ulgm_quiz_report_user_data', 'your_function_name', 10, 4 );

Parameters

$html_vars (mixed)
This parameter contains an array of variables used to build the HTML for the user report.
$quiz_ID (mixed)
This parameter is an array containing variables to be used for generating the HTML of the quiz report for individual users.
$group_ID (mixed)
This parameter contains the unique identifier for the quiz being reported on.
$group_users (mixed)
This parameter contains the ID of the group for which the quiz report is being generated.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'ulgm_quiz_report_user_data' filter to
 * add custom information to the user data displayed in the group quiz report.
 *
 * This example demonstrates adding a custom field to the user report
 * that shows the total number of attempts a user has made for a specific quiz.
 */
add_filter( 'ulgm_quiz_report_user_data', function( $html_vars, $quiz_ID, $group_ID, $group_users ) {

	// Check if we are processing data for a specific quiz and group.
	if ( ! empty( $quiz_ID ) && ! empty( $group_ID ) ) {

		// Iterate through each user in the group.
		foreach ( $group_users as $user_ID => $user_data ) {

			// Get the total number of attempts for this user and quiz.
			// This is a hypothetical function call, replace with actual logic
			// to fetch user quiz attempt data from your database or API.
			$user_quiz_attempts = your_custom_function_to_get_user_quiz_attempts( $user_ID, $quiz_ID );

			// Add the custom data to the $html_vars array for this user.
			// We'll store it under a new key, 'total_quiz_attempts'.
			if ( isset( $html_vars[ $user_ID ] ) && is_array( $html_vars[ $user_ID ] ) ) {
				$html_vars[ $user_ID ]['total_quiz_attempts'] = $user_quiz_attempts;
			}
		}
	}

	// Always return the modified $html_vars array.
	return $html_vars;

}, 10, 4 );

/**
 * Replace this with your actual function to retrieve user quiz attempt data.
 * This is a placeholder example.
 *
 * @param int $user_id The ID of the user.
 * @param int $quiz_id The ID of the quiz.
 * @return int The total number of attempts.
 */
function your_custom_function_to_get_user_quiz_attempts( $user_id, $quiz_id ) {
	// Example: Fetch from WordPress options or a custom table.
	// For demonstration, we'll return a random number.
	return rand( 0, 5 );
}

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-quiz-report.php:879

'quiz_modal' => $modal_link,
						'quiz_date'  => '__',
					);
				}
			}
		}

		return apply_filters( 'ulgm_quiz_report_user_data', $html_vars, $quiz_ID, $group_ID, $group_users );
	}

	/**
	 *
	 */
	public static function report_scripts() {
		self::enqueue_frontend_assets();


Scroll to Top