Filter uncanny-automator

uap_option_all_wplms_quizs

Filters the options for all WPLMS quizzes before they are displayed or saved.

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

Description

Filters the list of available WPLMS quiz options for Uncanny Automator. Developers can use this hook to add custom quiz data fields or modify existing ones, influencing which quiz details are available for use in automations.


Usage

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

Parameters

$option (mixed)
This parameter holds the current value of the option being filtered, which represents a list of WPLMS quizzes.

Return Value

The filtered value.


Examples

add_filter( 'uap_option_all_wplms_quizs', 'my_custom_wplms_quiz_options', 10, 1 );

/**
 * Adds custom options to the WPLMS Quiz selection in Uncanny Automator.
 *
 * This function demonstrates how to hook into the 'uap_option_all_wplms_quizs' filter
 * to modify the list of available WPLMS Quiz options within Uncanny Automator.
 * In this example, we're adding an option to select "All Quizzes" as a special case.
 *
 * @param array $option The original array of WPLMS Quiz options.
 * @return array The modified array of WPLMS Quiz options.
 */
function my_custom_wplms_quiz_options( $option ) {

	// Check if we're modifying the main quiz selection structure.
	// The 'value' key typically holds the associative array of quiz options.
	if ( isset( $option['value'] ) && is_array( $option['value'] ) ) {

		// Define the placeholder for an "All Quizzes" option.
		// This assumes the original structure uses a prefix for option codes.
		// We'll use a common prefix like 'wplms_quiz' for demonstration.
		// In a real scenario, you'd inspect $option_code from the source context.
		$option_code_prefix = 'wplms_quiz'; // This might need adjustment based on actual $option_code usage.

		// Add a new entry for "All Quizzes".
		// The key is the option code, and the value is the human-readable label.
		$option['value'][ $option_code_prefix . '_ALL' ] = esc_attr__( 'All WPLMS Quizzes', 'uncanny-automator' );

		// You could also potentially modify existing options if needed.
		// For instance, to change the label of a specific quiz:
		// if ( isset( $option['value']['wplms_quiz_123_ID'] ) ) {
		//     $option['value']['wplms_quiz_123_ID'] = esc_attr__( 'My Special Quiz', 'uncanny-automator' );
		// }
	}

	// Always return the modified (or original if no changes were made) 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/wplms/helpers/wplms-helpers.php:90

public function all_wplms_quizs( $label = null, $option_code = 'WPLMS_QUIZ', $any_option = true ) {

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

		$args = array(
			'post_type'      => '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' ),
				$option_code . '_THUMB_ID'  => esc_attr__( 'Quiz featured image ID', 'uncanny-automator' ),
				$option_code . '_THUMB_URL' => esc_attr__( 'Quiz featured image URL', 'uncanny-automator' ),
			),
		);

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

Scroll to Top