Filter uncanny-learndash-groups

quiz-report-table-strings

Filters the strings used in the quiz report table to allow for customization and localization.

add_filter( 'quiz-report-table-strings', $callback, 10, 1 );

Description

Filters the localized strings used in Uncanny Groups quiz reports. Developers can modify, add, or remove strings before they are displayed, allowing for complete customization of report labels and text to suit specific needs or languages. This hook fires when the localized strings array is being prepared for use in the frontend reports.


Usage

add_filter( 'quiz-report-table-strings', 'your_function_name', 10, 1 );

Parameters

$localized_strings (mixed)
This parameter is an associative array containing localized strings used in the quiz report table.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the localized strings for the quiz report table.
 *
 * This function demonstrates how to add, remove, or modify strings used in
 * the quiz report table generated by the Uncanny LearnDash Groups plugin.
 * For instance, we might want to add a new column label or change an existing one.
 *
 * @param array $localized_strings An array of strings used in the quiz report table.
 * @return array The modified array of localized strings.
 */
add_filter( 'quiz-report-table-strings', function( $localized_strings ) {

	// Add a new string for a custom column, for example, 'completionDate'.
	// This assumes you might have a custom column you want to display and localize.
	$localized_strings['completionDate'] = __( 'Date Completed', 'my-text-domain' );

	// Modify an existing string. Let's change the placeholder text for the search bar.
	// We'll add the word "course" to the search placeholder to make it more specific.
	if ( isset( $localized_strings['searchPlaceholder'] ) ) {
		$localized_strings['searchPlaceholder'] = sprintf(
			__( '%s, course, user, name, email, date or score', 'my-text-domain' ),
			LearnDash_Custom_Label::get_label( 'quiz' )
		);
	}

	// Remove a string if it's no longer needed. For example, if the 'csvExport'
	// functionality is disabled by another plugin or custom code.
	// Note: Be cautious when removing strings, ensure it aligns with your logic.
	// unset( $localized_strings['csvExport'] );

	// Reorder or add new elements to the 'tableLanguage' array if you're
	// also modifying the DataTables integration. This is a more advanced
	// use case and depends on the DataTables configuration within the plugin.
	// Example: adding a custom message for when no data is available.
	if ( isset( $localized_strings['tableLanguage']['emptyTable'] ) ) {
		$localized_strings['tableLanguage']['emptyTable'] = __( 'No quiz results found for the selected criteria.', 'my-text-domain' );
	}

	// Return the modified array of strings.
	return $localized_strings;
}, 10, 1 ); // Priority 10, accepts 1 argument.

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:995
src/classes/reports/group-assignments.php:870
src/classes/reports/group-essays.php:969

private static function get_frontend_localized_strings() {

		$localized_strings = array();

		$localized_strings['username']             = __( 'Username', 'uncanny-learndash-groups' );
		$localized_strings['userEmail']            = __( 'Email', 'uncanny-learndash-groups' );
		$localized_strings['firstName']            = __( 'First name', 'uncanny-learndash-groups' );
		$localized_strings['lastName']             = __( 'Last name', 'uncanny-learndash-groups' );
		$localized_strings['quizScore']            = sprintf( _x( '%s score', 'Quiz score', 'uncanny-learndash-groups' ), LearnDash_Custom_Label::get_label( 'quiz' ) );
		$localized_strings['detailedReport']       = __( 'Detailed report', 'uncanny-learndash-groups' );
		$localized_strings['date']                 = __( 'Date', 'uncanny-learndash-groups' );
		$localized_strings['csvExport']            = __( 'CSV export', 'uncanny-learndash-groups' );
		$localized_strings['selectCourse']         = sprintf( __( 'Select %s', 'uncanny-learndash-groups' ), LearnDash_Custom_Label::get_label( 'course' ) );
		$localized_strings['noCourse']             = sprintf( __( 'No %s available', 'uncanny-learndash-groups' ), LearnDash_Custom_Label::get_label( 'courses' ) );
		$localized_strings['selectUser']           = __( 'Select user', 'uncanny-learndash-groups' );
		$localized_strings['noUsers']              = __( 'No users available', 'uncanny-learndash-groups' );
		$localized_strings['all']                  = __( 'All', 'uncanny-learndash-groups' );
		$localized_strings['selectQuiz']           = sprintf( __( 'Select %s', 'uncanny-learndash-groups' ), LearnDash_Custom_Label::get_label( 'quiz' ) );
		$localized_strings['customizeColumns']     = __( 'Customize columns', 'uncanny-learndash-groups' );
		$localized_strings['hideCustomizeColumns'] = __( 'Hide customize columns', 'uncanny-learndash-groups' );

		/* DataTable */
		$localized_strings                      = array_merge( $localized_strings, Utilities::i18n_datatable_strings() );
		$localized_strings['searchPlaceholder'] = __( 'Search by username, name, email, date or score', 'uncanny-learndash-groups' );

		// Allow filtering
		$localized_strings = apply_filters( 'quiz-report-table-strings', $localized_strings );

		// Configure for JS
		$localized_strings['tableLanguage'] = array(
			'processing'        => $localized_strings['processing'],
			'search'            => '_INPUT_',
			'searchPlaceholder' => $localized_strings['searchPlaceholder'],
			'lengthMenu'        => $localized_strings['lengthMenu'],
			'info'              => $localized_strings['info'],
			'infoEmpty'         => $localized_strings['infoEmpty'],
			'infoFiltered'      => $localized_strings['infoFiltered'],
			'infoPostFix'       => '',
			'loadingRecords'    => $localized_strings['loadingRecords'],
			'zeroRecords'       => $localized_strings['zeroRecords'],
			'emptyTable'        => $localized_strings['emptyTable'],
			'paginate'          => array(
				'first'    => $localized_strings['paginate']['first'],
				'previous' => $localized_strings['paginate']['previous'],
				'next'     => $localized_strings['paginate']['next'],
				'last'     => $localized_strings['paginate']['last'],
			),
			'aria'              => array(
				'sortAscending'  => $localized_strings['sortAscending'],
				'sortDescending' => $localized_strings['sortDescending'],
			),
		);

		return $localized_strings;
	}

Scroll to Top