Filter uncanny-automator

uap_option_all_tutorlms_courses

Filters the options array for Tutor LMS courses, allowing modification before it's used.

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

Description

Filters the available options for selecting Tutor LMS courses, allowing developers to modify or extend the data fields that can be used in Uncanny Automator triggers and actions. This hook provides access to course ID, URL, featured image ID, and featured image URL.


Usage

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

Parameters

$option (mixed)
This parameter represents the label for the courses.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the 'uap_option_all_tutorlms_courses' hook.
 *
 * This function demonstrates adding a new option to the list of Tutor LMS course options
 * available in Uncanny Automator. In this specific example, we're adding an option
 * to retrieve the course author's display name.
 *
 * @param array $option The original array of course options.
 * @return array The modified array of course options with the new entry.
 */
function my_automator_add_tutorlms_course_author_option( $option ) {
	// Ensure the $option array has the expected structure before trying to modify it.
	if ( ! isset( $option['fields'] ) || ! is_array( $option['fields'] ) ) {
		return $option;
	}

	// We need to know the base option code to append our new field to the correct array.
	// In the source context, it seems like $option_code is derived from the outer array key.
	// Let's assume the relevant key is 'fields' which contains the actual option groups.
	// We'll iterate through the fields to find the one that likely contains the course options.
	foreach ( $option['fields'] as $field_key => $field_data ) {
		// This is a heuristic guess based on the common pattern of option keys.
		// A more robust solution might involve checking specific keys or values within $field_data.
		if ( str_contains( $field_key, '_COURSES' ) && isset( $field_data['options'] ) ) {
			// Assuming $field_data['options'] is the array where we need to add our new field.
			// We'll append '_AUTHOR_DISPLAY_NAME' as a new option.
			$option_code = $field_key; // Get the base code for this group of options.

			$option['fields'][ $field_key ]['options'][ $option_code . '_AUTHOR_DISPLAY_NAME' ] = esc_attr__( 'Course Author Display Name', 'your-text-domain' );
			break; // Assume we found the correct group and stop.
		}
	}

	return $option;
}
add_filter( 'uap_option_all_tutorlms_courses', 'my_automator_add_tutorlms_course_author_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

src/integrations/tutorlms/helpers/tutorlms-helpers.php:155

public function all_tutorlms_courses( $label = null, $option_code = 'TUTORLMSCOURSE', $all_label = false, $any_option = false ) {

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

		// post query arguments.
		$args = array(
			'post_type'      => tutor()->course_post_type,
			'posts_per_page' => 999,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => 'publish',

		);

		$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_html__( 'Any course', 'uncanny-automator' ), $all_label );

		$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__( 'Course title', 'uncanny-automator' ),
				$option_code . '_ID'        => esc_attr__( 'Course ID', 'uncanny-automator' ),
				$option_code . '_URL'       => esc_attr__( 'Course URL', 'uncanny-automator' ),
				$option_code . '_THUMB_ID'  => esc_attr__( 'Course featured image ID', 'uncanny-automator' ),
				$option_code . '_THUMB_URL' => esc_attr__( 'Course featured image URL', 'uncanny-automator' ),
			),
		);

		return apply_filters( 'uap_option_all_tutorlms_courses', $option );

	}

Scroll to Top