apply_filters( 'show_user_profile_quiz_statistics', boolean $show_stats, int $user_id, array $quiz_attempt, string $context )
Filters whether to Display User Quiz Statistics.
Description #
This filter allows display-time control over displaying the user quiz statistics link. This link is shown on the user profile when using the [ld_profile] shortcode, the Course Info Widget and the user’s WP Profile.
This filter is only called if the quiz_attempt contained the reference field ‘statistic_ref_id’ which links the user meta record to the statistics row. Also, the viewing user must a) match the used record being viewed OR b) be an administrator OR c) be a group leader and the user is within the group leader managed groups.
Parameters #
- $show_stats
-
(boolean) This will be true or false and determined from the 'View Profile Statistics' quiz setting.
- $user_id
-
(int) The ID of the user quiz to be displayed.
- $quiz_attempt
-
(array) This is the quiz attempt array read from the user meta.
- $context
-
(string) This will be the file where this filter is being called. Possible values are 'course_info_shortcode.php', 'profile.php' or other.
Source #
Examples #
Note: Extended code example below not guaranteed, you may need to consult with a developer
<?php
/**
* Example usage for show_user_profile_quiz_statistics filter.
*/
add_filter( 'show_user_profile_quiz_statistics', 'show_user_profile_quiz_statistics_proc', 10, 4 );
function show_user_profile_quiz_statistics_proc( $show_stats, $user_id, $quiz_attempt, $context = '' ) {
// Example of checking context match on some custom template
if ( 'test.php' == $context ) {
$show_stats = true;
} else {
$show_stats = false;
}
return $show_stats;
}
add_filter(
'show_user_profile_quiz_statistics',
function ( $can_view, $user_id = 0, $quiz_attempt = array(), $file = '' ) {
// Example 1: To override ALL quizzes setting.
$can_view = true;
// The $quiz_attempt array will look similar to the following
// Array
// (
// [quiz] => 103
// [score] => 2
// [count] => 2
// [question_show_count] => 2
// [pass] => 1
// [rank] => -
// [time] => 1492711057
// [pro_quizid] => 4
// [points] => 8
// [total_points] => 8
// [percentage] => 100
// [timespent] => 8.915
// [has_graded] =>
// [statistic_ref_id] => 1
// [started] => 1492711048
// [completed] => 1492711056
// )
// Example 2: Override only for specific Quiz Post $quiz_attempt['quiz'] value.
// If ( $quiz_attempt['quiz'] == 134 ) {
// $can_view = true;
// } else {
// $can_view = false;
// }
// Example 3: Override only for specific Quiz percentage.
// If ( $quiz_attempt['percentage'] > 95 ) {
// $can_view = true;
// } else {
// $can_view = false;
// }
// Always return $can_view
return $can_view;
},
10,
4
);
Changelog #
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |