Filter Since 2.3 uncanny-toolkit-pro

show_user_profile_quiz_statistics

Show user profile quiz statistics filter Filters user profile quiz statistics for a specific quiz attempt, allowing modification before display.

add_filter( 'show_user_profile_quiz_statistics', $callback, 10, 2 );

Description

Filters the display of quiz statistics on user profiles. Developers can use this hook to modify or completely replace the default quiz attempt data shown, providing custom reporting or hiding specific statistics. Fires after basic quiz attempt data is retrieved.


Usage

add_filter( 'show_user_profile_quiz_statistics', 'your_function_name', 10, 2 );

Parameters

$quiz_attempt (mixed)
- **$user_id** `mixed`
$quiz_attempt (mixed)
- **basename( __FILE__ )** `mixed`

Return Value

The filtered value.


Examples

/**
 * Example function to filter user profile quiz statistics.
 * This function checks if a specific statistic reference ID exists and, if so,
 * modifies the value returned by get_post_meta for '_viewProfileStatistics'.
 *
 * @param mixed $view_profile_statistics The value returned by get_post_meta( $quiz_attempt_post_id, '_viewProfileStatistics', true ).
 * @param int   $quiz_attempt_post_id    The post ID of the quiz attempt.
 * @param int   $user_id                 The ID of the user.
 * @param array $quiz_attempt            An array containing details of the quiz attempt.
 * @param string $file_basename          The basename of the file where the filter is applied.
 * @return mixed The potentially modified value for '_viewProfileStatistics'.
 */
function my_custom_quiz_statistics_filter( $view_profile_statistics, $quiz_attempt_post_id, $user_id, $quiz_attempt, $file_basename ) {
	// Let's imagine we only want to show statistics if the user has a 'premium_member' role.
	$user = get_user_by( 'id', $user_id );

	if ( ! $user || ! in_array( 'premium_member', (array) $user->roles ) ) {
		// If the user is not a premium member, return false to hide statistics.
		return false;
	}

	// You could also modify the existing value. For example, to append some custom text.
	if ( ! empty( $view_profile_statistics ) ) {
		$view_profile_statistics .= ' (Customized)';
	}

	// Always return the (potentially modified) value.
	return $view_profile_statistics;
}
add_filter( 'show_user_profile_quiz_statistics', 'my_custom_quiz_statistics_filter', 10, 5 );

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/templates/frontend-dashboard/dashboard-template.php:416

function learndash_get_step_permalink( $module_id, $course_id ) {
		return get_permalink( $module_id );
	}

Scroll to Top