Filter tin-canny-learndash-reporting

uotc_group_quiz_query_args

Filters the query arguments for retrieving group quiz data before it's fetched.

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

Description

Filters the arguments used to query group quizzes. Developers can modify the `$args` array to alter which quizzes are retrieved for a specific group, user, or user role, allowing for custom reporting or quiz filtering.


Usage

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

Parameters

$args (mixed)
This parameter is a mixed array containing arguments used to query quizzes within a specific group.
$group_id (mixed)
This parameter contains an array of arguments used to query quiz posts.
$user_id (mixed)
This parameter holds the ID of the group for which quizzes are being queried.
$user_role (mixed)
This parameter contains the ID of the user for whom the quiz data is being retrieved.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the query arguments for fetching group quizzes.
 *
 * This example demonstrates how to conditionally add a meta query to filter
 * quizzes based on a specific custom field, only if the user has a certain role.
 *
 * @param array  $args       The original query arguments for get_posts().
 * @param int    $group_id   The ID of the current group.
 * @param int    $user_id    The ID of the current user.
 * @param string $user_role  The role of the current user.
 * @return array The modified query arguments.
 */
add_filter( 'uotc_group_quiz_query_args', function( $args, $group_id, $user_id, $user_role ) {
    // Check if the current user has a specific role, e.g., 'group_leader'
    if ( $user_role === 'group_leader' ) {
        // Ensure 'meta_query' is an array, initialize if not set
        if ( ! isset( $args['meta_query'] ) || ! is_array( $args['meta_query'] ) ) {
            $args['meta_query'] = array();
        }

        // Add a meta query to include only quizzes marked as 'premium'
        // This is just an example; replace 'quiz_premium_status' and 'premium' with your actual meta key and value.
        $args['meta_query'][] = array(
            'key'     => 'quiz_premium_status',
            'value'   => 'premium',
            'compare' => '=',
        );
    }

    // Always return the (potentially modified) arguments
    return $args;
}, 10, 4 );
?>

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/group-quiz-report.php:889

'value'   => $course_ids,
						),
					);
				}
			}

			// Allow Query Args to be filtered
			$args    = apply_filters( 'uotc_group_quiz_query_args', $args, $group_id, $user_id, $user_role );
			$quizzes = get_posts( $args );

			// Filter shared steps quizzes.
			if ( $filter_shared ) {
				$quizzes = $this->filter_shared_steps_quizzes( $quizzes, $course_ids );
			}

Scroll to Top