Filter tin-canny-learndash-reporting

uo_tincanny_reporting_questions_quiz_dropdown_title

Filters the title displayed for the quiz dropdown in Tincanny reporting.

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

Description

Filters the title displayed in the quiz dropdown within the Uncanny Toolkit's Question Analysis Report. This allows developers to customize the default "Select a Quiz" text, offering dynamic options based on quiz ID or name for advanced reporting scenarios.


Usage

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

Parameters

$quiz_id_html (mixed)
This parameter contains the HTML representation of the quiz ID for the dropdown.
$quiz_id_html (mixed)
The HTML representation of the quiz ID within the dropdown.
$quiz_name (mixed)
The ID of the quiz that is currently selected in the dropdown.
$quiz_id (mixed)
This parameter contains the ID of the selected quiz as a mixed type.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the quiz dropdown title to include the quiz title if available.
 *
 * This callback function checks if a quiz name is provided and, if so,
 * prepends it to the existing dropdown title, making it easier for users
 * to identify the quiz.
 *
 * @param string $quiz_id_html The current HTML representation of the quiz ID.
 * @param string $quiz_name     The name of the quiz.
 * @param int    $quiz_id       The ID of the quiz.
 * @return string The modified quiz dropdown title.
 */
add_filter( 'uo_tincanny_reporting_questions_quiz_dropdown_title', function( $quiz_id_html, $quiz_name, $quiz_id ) {
    // The original filter provides $quiz_id_html twice. We'll use the last occurrence.
    // Let's assume the order is actually: $quiz_id_html, $quiz_name, $quiz_id
    // And the first parameter is the combined string we want to modify.

    // Check if $quiz_name is not empty and is a string.
    if ( ! empty( $quiz_name ) && is_string( $quiz_name ) ) {
        // Prepend the quiz name to the existing title.
        // The original title is often just the ID like "(ID: 123) ".
        // We want to make it more readable, e.g., "My Awesome Quiz (ID: 123)".
        // Ensure we don't duplicate the ID part if it's already there.
        if ( strpos( $quiz_id_html, '(ID: ' . $quiz_id . ')' ) !== false ) {
            // Remove the ID part from $quiz_id_html and prepend the quiz name.
            $quiz_id_only_html = '(ID: ' . $quiz_id . ') ';
            $quiz_title_only = str_replace( $quiz_id_only_html, '', $quiz_id_html );
            return $quiz_name . ' ' . $quiz_id_only_html;
        } else {
            // If the ID part isn't found as expected, just prepend the quiz name.
            return $quiz_name . ' ' . $quiz_id_html;
        }
    }

    // If no quiz name is available or it's not a string, return the original value.
    return $quiz_id_html;
}, 10, 4 ); // Priority 10, accepting 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:333

private static function generate_quiz_dropdown( $quizzes ) {
		$drop_down = '<select id="uotc-question-report-group" name="quiz-id">';
		$drop_down .= sprintf(
			// translators: %s is select quiz text
			'<option value="0">%s</option>',
			sprintf(
				// translators: %s is the quiz label
				esc_html__( 'Select a %s', 'uncanny-learndash-reporting' ),
				LearnDash_Custom_Label::label_to_lower( 'quiz' )
			)
		);

		foreach ( $quizzes as $quiz_id => $quiz_name ) {
			$selected         = absint( ultc_get_filter_var( 'quiz-id', 0 ) ) === $quiz_id ? ' selected="selected"' : '';
			$quiz_id_html     = '(ID: ' . $quiz_id . ') ';
			$quiz_in_dropdown = apply_filters( 'uo_tincanny_reporting_questions_quiz_dropdown_title', "$quiz_id_html $quiz_name", $quiz_id_html, $quiz_name, $quiz_id );
			$drop_down        .= '<option value="' . esc_attr( $quiz_id ) . '" ' . $selected . '>' . esc_html( $quiz_in_dropdown ) . '</option>';
		}
		$drop_down      .= '</select>';
		self::$dropdown = $drop_down;
	}

Scroll to Top