uo_tincanny_reporting_questions_dropdowns
Fires after the reporting questions dropdowns are generated, allowing modification before output.
add_action( 'uo_tincanny_reporting_questions_dropdowns', $callback, 10, 3 );
Description
Fires after the questions dropdowns are displayed in the Uncanny Toolkit's Question Analysis Report. Developers can use this hook to modify the questions dropdowns, add custom filters, or perform other actions related to question selection before the report form is submitted. The hook passes the current questions, quiz ID, pro quiz ID, and class instance.
Usage
add_action( 'uo_tincanny_reporting_questions_dropdowns', 'your_function_name', 10, 3 );
Parameters
-
$questions(mixed) - This parameter contains an array or object representing the available quiz questions, which are used to populate a dropdown menu in the reporting interface.
-
$quiz_id(mixed) - This parameter contains an array or similar data structure that holds information about the questions available for reporting.
-
$pro_quiz_id(mixed) - This parameter contains the ID of the quiz for which reporting questions are being displayed.
Examples
<?php
/**
* Example function to modify the questions dropdowns for the Uncanny Toolkit's Tincanny reporting.
* This function might be used to add a new filter option to the questions dropdown,
* for example, to filter by question type or by a specific tag.
*
* @param array $questions The current array of questions data.
* @param int $quiz_id The ID of the quiz.
* @param int $pro_quiz_id The Pro Quiz ID.
* @param string $class The name of the class calling the action.
*/
add_action( 'uo_tincanny_reporting_questions_dropdowns', function ( $questions, $quiz_id, $pro_quiz_id, $class ) {
// Check if the current user has the capability to manage the reports.
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// Let's assume we want to add a filter for questions marked as 'important'.
// This is a hypothetical scenario. In a real plugin, you'd have a way
// to mark questions as important, perhaps via meta data.
$important_questions_count = 0;
if ( is_array( $questions ) ) {
foreach ( $questions as $question ) {
// Hypothetical check: if the question has a meta key 'is_important' set to true.
// In a real scenario, you would fetch this data from your quiz/question structure.
if ( isset( $question['meta']['is_important'] ) && $question['meta']['is_important'] ) {
$important_questions_count++;
}
}
}
// If there are any important questions, display a new option in the dropdown.
if ( $important_questions_count > 0 ) {
// This assumes that the existing dropdown is generated by echo-ing HTML.
// We're appending a new option to a hypothetical select element.
// In a real implementation, you might modify $questions directly or
// inject HTML that gets rendered elsewhere. For this example, we'll
// output a message indicating this functionality.
// Note: The original code structure implies $dropdown is echoed directly.
// To *modify* existing dropdowns, you'd typically need to capture the output
// of the original dropdown and modify it, or hook into a filter that returns
// the dropdown HTML. Since this is an 'action', we are adding *new* elements.
// A more realistic approach might involve dynamically adding an option to an existing <select> element.
// However, without knowing the exact structure of `self::$dropdown`, we'll illustrate
// adding a new filter choice.
// Let's simulate adding an option to a hypothetical filter selection.
// This assumes the existing form has a dropdown for filtering questions.
// We are adding a new choice to that dropdown.
// This is a placeholder. You would replace this with actual HTML generation
// to add a new option to the form's question filter.
// For example, if the form had:
// <select name="question_filter">
// <option value="all">All Questions</option>
// ...
// </select>
// You would add:
// <option value="important">Important Questions (<?php echo $important_questions_count; ?>)</option>
// For this example, we'll simply output a message that would typically be part of a select option.
// This is a simplification because the actual DOM manipulation would be more complex
// if you're not directly generating the HTML for the dropdown here.
// The `__CLASS__` parameter is often used to get the fully qualified class name.
// We could use it to conditionally apply logic based on where it's being called.
// Example: Dynamically add a new option to a filter.
// This requires you to know how the existing dropdown is rendered and where to insert.
// Since we are in an `action` hook, we can't directly modify the `$questions` array to alter the dropdown logic itself.
// We are adding *new* UI elements or modifying behavior *around* the existing dropdowns.
// Let's assume `self::$dropdown` outputs a <select> tag. We can't directly add an option to it here.
// A more practical use case for this action might be to add a separate filter control,
// or to modify the behavior of the search button based on selected options.
// For the purpose of demonstrating realistic logic within this hook:
// We'll add a hidden input field that could be used by JavaScript to filter
// the questions displayed *after* the page loads, or it could be submitted with the form.
// We can leverage the $quiz_id and $pro_quiz_id to fetch additional data if needed.
// For example, to get quiz-specific settings that might influence filtering.
echo '<input type="hidden" name="uo_tincanny_quiz_id" value="' . esc_attr( $quiz_id ) . '">';
echo '<input type="hidden" name="uo_tincanny_pro_quiz_id" value="' . esc_attr( $pro_quiz_id ) . '">';
// Imagine you have a way to fetch quiz-specific tags.
// $quiz_tags = get_post_meta( $quiz_id, '_uncanny_quiz_tags', true );
// if ( ! empty( $quiz_tags ) ) {
// echo '<label for="uo_tincanny_tag_filter">Filter by Tag:</label>';
// echo '<select name="uo_tincanny_tag_filter">';
// echo '<option value="">All Tags</option>';
// foreach ( $quiz_tags as $tag ) {
// echo '<option value="' . esc_attr( sanitize_title( $tag ) ) . '">' . esc_html( $tag ) . '</option>';
// }
// echo '</select>';
// }
}
}, 10, 4 ); // Priority 10, accepts 4 arguments
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/uncanny-question-analysis-report/question-analysis-report.php:855
<div class="uotc-question-report__selects">
<div id="uotc-question-report-selections">
<form method="get">
<?php echo self::$dropdown; ?>
<?php echo self::$date_range; ?>
<?php do_action( 'uo_tincanny_reporting_questions_dropdowns', self::$questions, self::$quiz_id, self::$pro_quiz_id, __CLASS__ ); ?>
<p>
<input type="submit" class="uotc-question-report-submit" value="Search"/>
</p>
</form>
</div>
</div>
</div>