Filter
uncanny-automator
uap_option_all_tutorlms_quizzes
Filters all Tutor LMS quiz options before they are retrieved, allowing for modification.
add_filter( 'uap_option_all_tutorlms_quizzes', $callback, 10, 1 );
Description
This filter hook fires after all Tutor LMS quizzes have been retrieved. Developers can use it to modify the array of quiz options before they are displayed in Uncanny Automator. This allows for custom filtering, adding new quiz-related data, or removing unwanted options.
Usage
add_filter( 'uap_option_all_tutorlms_quizzes', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the option array being filtered, allowing modifications to the list of Tutor LMS quizzes.
Return Value
The filtered value.
Examples
<?php
/**
* Filters the list of Tutor LMS quizzes to exclude quizzes marked as drafts.
*
* This function demonstrates how to use the 'uap_option_all_tutorlms_quizzes'
* filter to modify the array of available Tutor LMS quizzes.
*
* @param array $option The original array of quiz options, including 'label' and 'options'.
* @return array The modified array of quiz options, with draft quizzes removed.
*/
function my_automator_filter_tutorlms_quizzes( $option ) {
// Ensure we are working with the correct structure and data.
if ( ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
return $option;
}
$filtered_quizzes = array();
$tutor_quizzes = $option['options'];
// Iterate through each quiz and check its status.
// We assume a Tutor LMS quiz object has a 'status' property.
foreach ( $tutor_quizzes as $quiz_id => $quiz_data ) {
// Assuming $quiz_data is an object or array that contains quiz details.
// We'll simulate checking for a 'status' key. In a real scenario,
// you'd inspect the actual structure returned by Tutor LMS.
// For this example, let's assume a 'status' key exists and 'draft' is a possible value.
// If the quiz status is not 'draft', we include it.
if ( isset( $quiz_data['status'] ) && 'draft' !== $quiz_data['status'] ) {
$filtered_quizzes[ $quiz_id ] = $quiz_data;
} elseif ( ! isset( $quiz_data['status'] ) ) {
// If the status key is missing, assume it's not a draft and include it.
// This is a fallback for older or unexpected data structures.
$filtered_quizzes[ $quiz_id ] = $quiz_data;
}
}
// Update the options with the filtered quizzes.
$option['options'] = $filtered_quizzes;
return $option;
}
add_filter( 'uap_option_all_tutorlms_quizzes', 'my_automator_filter_tutorlms_quizzes', 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/integrations/tutorlms/helpers/tutorlms-helpers.php:198
public function all_tutorlms_quizzes( $label = null, $option_code = 'TUTORLMSQUIZ', $any_option = false ) {
if ( ! $label ) {
$label = esc_attr__( 'Quiz', 'uncanny-automator' );
}
// post query arguments.
$args = array(
'post_type' => 'tutor_quiz',
'posts_per_page' => 999,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any quiz', 'uncanny-automator' ) );
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
// to setup example, lets define the value the child will be based on
'current_value' => false,
'validation_type' => 'text',
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Quiz title', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr__( 'Quiz ID', 'uncanny-automator' ),
$option_code . '_URL' => esc_attr__( 'Quiz URL', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_all_tutorlms_quizzes', $option );
}