Filter uncanny-automator

uap_option_all_tutorlms_lessons

Filters all Tutor LMS lessons before they are retrieved, allowing modification of the lesson data.

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

Description

Filter available Tutor LMS lesson data options. This hook allows developers to add custom fields or modify existing ones, such as Lesson ID, URL, or featured image details, for use within Uncanny Automator. Modify the `$option` array to extend or alter lesson data available to triggers and actions.


Usage

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

Parameters

$option (mixed)
This parameter is used to specify the label for the lessons, defaulting to 'Lesson' if not provided.

Return Value

The filtered value.


Examples

// Example: Add a custom option to the TutorLMS lessons dropdown, maybe for a specific lesson type.
add_filter(
	'uap_option_all_tutorlms_lessons',
	function ( $option ) {
		// Assuming $option is an array and we want to add a new entry.
		// In a real scenario, you'd want to be more specific about the structure of $option.
		// For this example, let's assume $option['lessons'] is where the lesson options are stored.

		if ( isset( $option['lessons'] ) && is_array( $option['lessons'] ) ) {
			// Let's say we want to add a "Lesson Title" option.
			// We'll use a placeholder $option_code here, as the actual code would be dynamically generated in the source.
			$custom_option_code = 'MY_CUSTOM_LESSON_TITLE'; // Example custom code
			$option['lessons'][ $custom_option_code ] = __( 'Lesson Title', 'uncanny-automator' );
		}

		return $option;
	},
	10, // Priority
	1  // Accepted args count
);

// Example: Filter out lessons that have a specific tag or category.
add_filter(
	'uap_option_all_tutorlms_lessons',
	function ( $option ) {
		// This example assumes the $option array contains a 'lessons' key which is an array of lesson data.
		// It also assumes each lesson item has a 'ID' and potentially other fields that can be accessed.
		// In a real-world scenario, you would need to inspect the actual structure of $option
		// and the individual lesson items to make this logic accurate.

		// For demonstration, let's imagine we want to exclude lessons that have a specific meta key value.
		// We'll simulate this by adding a check.

		if ( isset( $option['lessons'] ) && is_array( $option['lessons'] ) ) {
			$filtered_lessons = [];
			foreach ( $option['lessons'] as $key => $lesson_data ) {
				// Example: Check if lesson has a meta key 'exclude_from_automator' set to 'yes'
				// This requires fetching lesson meta, which might not be directly available in $lesson_data.
				// In a real integration, you might need to make a WP_Query or get_post_meta.
				// For this stub, we'll assume a hypothetical structure.
				$lesson_id = $lesson_data['ID'] ?? null; // Assuming 'ID' is available

				if ( $lesson_id ) {
					$exclude_meta = get_post_meta( $lesson_id, 'exclude_from_automator', true );
					if ( 'yes' === $exclude_meta ) {
						continue; // Skip this lesson
					}
				}

				$filtered_lessons[ $key ] = $lesson_data;
			}
			$option['lessons'] = $filtered_lessons;
		}

		return $option;
	},
	20, // Priority (lower priority to run after initial setup if needed)
	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:110

public function all_tutorlms_lessons( $label = null, $option_code = 'TUTORLMSLESSON', $any_option = false ) {

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

		// post query arguments.
		$args = array(
			'post_type'      => tutor()->lesson_post_type,
			'posts_per_page' => 999,
			'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' ),
			),
		);

		return apply_filters( 'uap_option_all_tutorlms_lessons', $option );

	}

Scroll to Top