Filter uncanny-automator

uap_option_all_lf_quizs

Filters the quiz IDs included in the "all" LifterLMS quiz list.

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

Description

Filters the array of available LifterLMS quiz options for Uncanny Automator. Developers can use this to add, remove, or modify quiz data points (like title, ID, or URL) that can be used in Automator recipes. This hook fires when building the dropdown for selecting a LifterLMS quiz.


Usage

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

Parameters

$option (mixed)
This parameter holds the value of the 'Quiz' label, which can be modified by filters.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the uap_option_all_lf_quizs filter to modify the available LifterLMS quiz options.
 *
 * This filter allows you to add, remove, or modify the data points available when setting up
 * automations related to LifterLMS quizzes within Uncanny Automator.
 *
 * @param array $option The array of quiz options to be filtered.
 * @return array The modified array of quiz options.
 */
add_filter( 'uap_option_all_lf_quizs', 'my_custom_lf_quiz_options', 10, 1 );

function my_custom_lf_quiz_options( $option ) {

	// Let's say we want to add an option for the 'Quiz Completion Date'.
	// We need to define a unique key for this new option.
	$new_option_key = 'quiz_completion_date';

	// We also need to provide a user-friendly label for this option.
	$new_option_label = esc_attr__( 'Quiz Completion Date', 'my-text-domain' );

	// Add the new option to the existing array of options.
	// The structure expects an array of key => label pairs.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
		$option['options'][ $new_option_key ] = $new_option_label;
	}

	// Optionally, we could also modify the 'custom_value_description'.
	// For this example, let's keep it as is, but you could change it if needed.
	// $option['custom_value_description'] = esc_attr__( 'Completion Date', 'my-text-domain' );

	// It's important to always return the modified array.
	return $option;
}
?>

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/lifterlms/helpers/lifterlms-helpers.php:265

public function all_lf_quizs( $label = null, $option_code = 'LFQUIZ', $any_option = true ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Quiz', 'uncanny-automator' );
		}

		$args = array(
			'post_type'      => 'llms_quiz',
			'posts_per_page' => 9999,
			'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' ),
			),
			'custom_value_description' => esc_attr__( 'Quiz ID', 'uncanny-automator' ),
		);

		return apply_filters( 'uap_option_all_lf_quizs', $option );
	}

Scroll to Top