Filter uncanny-automator

uap_option_all_lf_lessons

Filters LifterLMS lessons options for customization before they are saved or displayed.

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

Description

This filter allows developers to modify the array of available options for LifterLMS lessons in Uncanny Automator. It's used when generating dynamic dropdowns for recipes, enabling the addition or alteration of lesson-related data fields like titles, IDs, and URLs. The `$option` parameter contains the current array of lesson options.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Add a new option to the LifterLMS lessons dropdown.
 *
 * This function demonstrates how to hook into the 'uap_option_all_lf_lessons' filter
 * to add a custom option to the dynamic data dropdown for LifterLMS lessons.
 * We'll add an option to select the lesson title.
 *
 * @param array $option The current array of options for LifterLMS lessons.
 * @return array The modified array of options.
 */
add_filter( 'uap_option_all_lf_lessons', 'my_custom_uap_lesson_option', 10, 1 );

function my_custom_uap_lesson_option( $option ) {
    // Ensure $option is an array and has the expected structure before modification.
    if ( ! is_array( $option ) || ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
        return $option;
    }

    // Determine the base option code. This is likely derived from context or a predefined variable.
    // In a real scenario, you might need to inspect the $option array or have knowledge
    // of how $option_code is generated in the original plugin.
    // For this example, let's assume $option_code is 'LF_LESSON' as per the context snippet.
    $option_code_prefix = 'LF_LESSON'; // This might need to be dynamically determined if not constant.

    // Add a new option for the lesson title.
    $option['options'][ $option_code_prefix . '_TITLE' ] = esc_attr__( 'Lesson Title', 'uncanny-automator' );

    // You could also add other relevant lesson data if available through LifterLMS functions.
    // For instance, if there was a way to get the author ID:
    // $option['options'][ $option_code_prefix . '_AUTHOR_ID' ] = esc_attr__( 'Lesson Author ID', 'uncanny-automator' );

    // The 'custom_value_description' typically describes what the *ID* represents.
    // If we are adding 'Lesson Title', the custom value associated might still be the Lesson ID,
    // and the description correctly points to that. We'll leave it as is.
    // $option['custom_value_description'] = esc_attr__( 'Lesson ID', 'uncanny-automator' );

    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:135

public function all_lf_lessons( $label = null, $option_code = 'LFLESSON', $any_option = true ) {

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

		$args = array(
			'post_type'      => 'lesson',
			'posts_per_page' => 9999,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => 'publish',
		);

		$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any lesson', '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__( 'Lesson title', 'uncanny-automator' ),
				$option_code . '_ID'        => esc_attr__( 'Lesson ID', 'uncanny-automator' ),
				$option_code . '_URL'       => esc_attr__( 'Lesson URL', 'uncanny-automator' ),
				$option_code . '_THUMB_ID'  => esc_attr__( 'Lesson featured image ID', 'uncanny-automator' ),
				$option_code . '_THUMB_URL' => esc_attr__( 'Lesson featured image URL', 'uncanny-automator' ),
			),
			'custom_value_description' => esc_attr__( 'Lesson ID', 'uncanny-automator' ),
		);

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

Scroll to Top