Filter uncanny-automator-pro

uap_option_all_ld_quizzes

Filters the list of all LearnDash quizzes available for United Authors Pro integration.

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

Description

Filters the options array for LearnDash quizzes available as tokens in Uncanny Automator. Developers can use this hook to add or modify tokens related to LearnDash quizzes, such as custom quiz data or metadata, before they are displayed in the Uncanny Automator token selector. This allows for deeper integration and more advanced automation scenarios involving LearnDash quizzes.


Usage

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

Parameters

$option (mixed)
This parameter contains the current value of the `$option` being filtered.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the array of LearnDash quizzes for Uncanny Automator Pro,
 * potentially adding or filtering quizzes based on custom criteria.
 *
 * @param array $option The original array of LearnDash quizzes.
 * @return array The modified array of LearnDash quizzes.
 */
add_filter( 'uap_option_all_ld_quizzes', function( $option ) {

    // Example: Add a custom quiz to the list if it meets specific criteria.
    // In a real-world scenario, you might fetch this from post types,
    // a custom table, or based on user roles.
    $custom_quiz_id = 12345; // Replace with a real custom quiz ID.
    $custom_quiz_title = 'My Special Automated Quiz';
    $custom_quiz_url = get_permalink( $custom_quiz_id );

    // Check if the custom quiz actually exists and is published.
    if ( $custom_quiz_id && get_post_status( $custom_quiz_id ) === 'publish' ) {
        $option['options'][ 'custom_ld_quiz_' . $custom_quiz_id ] = array(
            'value'             => $custom_quiz_id,
            'label'             => esc_html( $custom_quiz_title ),
            'options'           => array(
                'custom_ld_quiz_' . $custom_quiz_id => esc_html__( 'My Special Automated Quiz title', 'your-text-domain' ),
                'custom_ld_quiz_' . $custom_quiz_id . '_ID' => esc_html__( 'My Special Automated Quiz ID', 'your-text-domain' ),
                'custom_ld_quiz_' . $custom_quiz_id . '_URL' => esc_html__( 'My Special Automated Quiz URL', 'your-text-domain' ),
            ),
            'type'              => 'learndash_quiz', // Assuming a type to identify it.
            'id'                => $custom_quiz_id,
            'href'              => $custom_quiz_url,
            'is_custom'         => true, // Flag to indicate it's custom.
        );
    }

    // Example: Remove a specific quiz if it's present.
    $quiz_to_remove_id = 98765; // Replace with a real quiz ID to remove.
    if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
        foreach ( $option['options'] as $key => $quiz_data ) {
            // Assuming quizzes are stored with keys like 'ld_quiz_12345' or 'custom_ld_quiz_12345'
            if ( strpos( $key, '_' ) !== false ) {
                $current_quiz_id = end( explode( '_', $key ) );
                if ( is_numeric( $current_quiz_id ) && intval( $current_quiz_id ) === $quiz_to_remove_id ) {
                    unset( $option['options'][ $key ] );
                }
            }
        }
    }

    return $option;
}, 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

uncanny-automator-pro/src/integrations/learndash/helpers/learndash-pro-helpers.php:1519

public function all_ld_quizzes( $label = null, $option_code = 'LD_QUIZZES', $is_any = false, $is_all = false, $supports_custom_value = false ) {

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

		$any     = true === $is_any ? esc_attr__( 'Any quiz', 'uncanny-automator-pro' ) : false;
		$any     = true === $is_all ? esc_attr__( 'All quizzes', 'uncanny-automator-pro' ) : $any;
		$options = $this->get_all_quiz_options( $any );

		$option = array(
			'option_code'           => $option_code,
			'label'                 => $label,
			'input_type'            => 'select',
			'required'              => true,
			'options'               => $options,
			'is_ajax'               => true,
			'fill_values_in'        => 'LD_QUESTIONS',
			'endpoint'              => 'ld_select_quiz_questions',
			'options_show_id'       => true,
			'supports_custom_value' => $supports_custom_value,
			'relevant_tokens'       => array(
				$option_code          => esc_attr__( 'Quiz title', 'uncanny-automator-pro' ),
				$option_code . '_ID'  => esc_attr__( 'Quiz ID', 'uncanny-automator-pro' ),
				$option_code . '_URL' => esc_attr__( 'Quiz URL', 'uncanny-automator-pro' ),
			),
		);

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

Scroll to Top