Filter tin-canny-learndash-reporting

learndash_date_time_formats

Filters the date and time format string used throughout LearnDash, allowing customization of how dates and times are displayed.

add_filter( 'learndash_date_time_formats', $callback, 10, 1 );

Description

This filter hook allows developers to modify the date and time format used for displaying quiz report data. It defaults to WordPress's configured date and time formats. Use this hook to customize how dates and times appear in quiz reports.


Usage

add_filter( 'learndash_date_time_formats', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the date and time format used in LearnDash reports.
 * This example will append '(UTC)' to the default date and time format if the
 * report is being viewed on the frontend and the user is not an administrator.
 *
 * @param string $date_time_format The current date and time format string.
 * @return string The modified date and time format string.
 */
add_filter( 'learndash_date_time_formats', function( $date_time_format ) {

	// Check if we are on the frontend and the current user is not an administrator.
	// This is a hypothetical scenario where you might want to show a different
	// format or indicate UTC for non-admin users on the frontend.
	if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
		// Append '(UTC)' to the format string.
		// In a real-world scenario, you might want to dynamically determine if
		// UTC is actually the timezone being displayed or offer a user-specific setting.
		return $date_time_format . ' (UTC)';
	}

	// Return the original format if the conditions are not met.
	return $date_time_format;

}, 10, 1 );
?>

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/reporting/learndash/frontend-reports/quiz-module-reports.php:458
src/reporting/learndash/frontend-reports/quiz-module-reports.php:980

$tc_quizzes = $wpdb->get_results( $q );

			// Lets cache the results
			$this->set_cache( $data_cache_key, $tc_quizzes );
		}

		$display_format = apply_filters( 'learndash_date_time_formats', get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );

		$keep_report_first_entry = apply_filters( 'uo_tincanny_quiz_report_module_first_entry', false );

		// Loop through H5P completed and answered modules
		foreach ( $tc_quizzes as $_quiz ) {

			// Sanity check that the result is valid


Scroll to Top