ulgm_quiz_report_get_groups_drop_downs
Filters the group dropdowns for quiz reports, allowing modification before they are displayed to users.
add_filter( 'ulgm_quiz_report_get_groups_drop_downs', $callback, 10, 2 );
Description
Filters the data used to generate dropdowns for group quiz reports. Modify the `$drop_down` array to customize which courses and quizzes are displayed for a specific user. This hook fires after initial dropdown data is prepared.
Usage
add_filter( 'ulgm_quiz_report_get_groups_drop_downs', 'your_function_name', 10, 2 );
Parameters
-
$drop_down(mixed) - This parameter holds an array containing the HTML for dropdown options representing courses and quizzes.
-
$user_id(mixed) - This parameter is a mixed type variable that will eventually hold an array of HTML `<option>` elements representing available courses and quizzes.
Return Value
The filtered value.
Examples
add_filter( 'ulgm_quiz_report_get_groups_drop_downs', 'my_custom_ulgm_quiz_report_groups_dropdowns', 10, 2 );
/**
* Example function to modify the dropdowns for the Uncanny Groups quiz report.
*
* This function demonstrates how to add custom options or modify existing ones
* for the course and quiz dropdowns in the Uncanny Groups quiz report.
*
* @param array $drop_down An array containing the default dropdown options for 'courses' and 'quizzes'.
* @param int $user_id The ID of the user for whom the report is being generated.
* @return array The modified dropdown options.
*/
function my_custom_ulgm_quiz_report_groups_dropdowns( $drop_down, $user_id ) {
// Example: Add a custom option to the courses dropdown.
// In a real-world scenario, you'd likely query for specific courses
// based on the user_id or other criteria.
$custom_course_option = '<option value="custom_course_1">' . esc_html__( 'My Special Course', 'uncanny-learndash-groups' ) . '</option>';
// Prepend the custom option to the existing courses dropdown.
// We're assuming $drop_down['courses'] contains HTML string of <option> tags.
// A more robust solution might involve parsing HTML or returning structured data.
if ( strpos( $drop_down['courses'], 'No results' ) !== false ) {
$drop_down['courses'] = $custom_course_option;
} else {
$drop_down['courses'] = $custom_course_option . $drop_down['courses'];
}
// Example: Modify the quizzes dropdown if it's for a specific user.
if ( $user_id === 123 ) { // Replace 123 with an actual user ID for testing
$drop_down['quizzes'] = '<option value="special_quiz_abc">' . esc_html__( 'Admin Specific Quiz', 'uncanny-learndash-groups' ) . '</option>';
$drop_down['quizzes'] .= '<option value="quiz_xyz">' . esc_html__( 'Another Admin Quiz', 'uncanny-learndash-groups' ) . '</option>';
}
// It's crucial to return the modified $drop_down array.
return $drop_down;
}
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:568
// Get Courses
$drop_down['courses'] = '<option>' . esc_html__( 'No results', 'uncanny-learndash-groups' ) . '</option>';
// Get Quizzes
$drop_down['quizzes'] = '<option>' . esc_html__( 'No results', 'uncanny-learndash-groups' ) . '</option>';
$drop_down = apply_filters( 'ulgm_quiz_report_get_groups_drop_downs', $drop_down, $user_id );
return $drop_down;
}
/**
* Get groups course quizzes
*