Filter
uncanny-automator
uap_option_all_lf_courses
Filters the list of all LifterLMS courses available for a specific option.
add_filter( 'uap_option_all_lf_courses', $callback, 10, 1 );
Description
Filters the array of LifterLMS course options, allowing developers to modify or add course-related data points available in Uncanny Automator. Use this to customize how courses are represented in automations and triggers.
Usage
add_filter( 'uap_option_all_lf_courses', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter holds the current value of the option being filtered.
Return Value
The filtered value.
Examples
<?php
/**
* Modify the LifterLMS course options array to include additional course data.
*
* This example demonstrates how to use the 'uap_option_all_lf_courses' filter
* to add custom course information to the available options for Uncanny Automator.
*
* @param array $option The original array of LifterLMS course options.
* @return array The modified array of LifterLMS course options.
*/
add_filter( 'uap_option_all_lf_courses', function( $option ) {
// Get all LifterLMS courses.
$courses = get_posts( array(
'post_type' => 'llms_course',
'posts_per_page' => -1,
'post_status' => 'publish',
) );
// If no courses are found, return the original option.
if ( empty( $courses ) ) {
return $option;
}
// Prepare an array to hold the additional course options.
$additional_course_options = array();
foreach ( $courses as $course ) {
// Construct a unique option code for each course.
$option_code_prefix = 'LLMS_COURSE_' . $course->ID;
// Add custom options for each course.
$additional_course_options[ $option_code_prefix . '_CUSTOM_FIELD' ] = sprintf(
esc_attr__( 'Custom Field for %s', 'uncanny-automator' ),
$course->post_title
);
// You could add more custom fields here based on your needs.
// For example:
// $additional_course_options[ $option_code_prefix . '_ANOTHER_FIELD' ] = sprintf(
// esc_attr__( 'Another Custom Field for %s', 'uncanny-automator' ),
// $course->post_title
// );
}
// Merge the additional course options into the existing 'options' array.
// Assuming the structure is an array of arrays, where the first key is the group title.
// We need to find the correct group to add our options to.
// Based on the source context, it seems like the 'options' key contains the actual options.
if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
$option['options'] = array_merge( $option['options'], $additional_course_options );
} else {
// If the structure is different, adjust this logic accordingly.
// For demonstration, let's assume a simpler structure if 'options' key is missing.
$option = array_merge( $option, $additional_course_options );
}
// Return the modified option array.
return $option;
}, 10, 1 ); // The priority is 10, and it accepts 1 argument.
?>
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:91
public function all_lf_courses( $label = null, $option_code = 'LFCOURSE', $any_option = true ) {
if ( ! $label ) {
$label = esc_attr__( 'Course', 'uncanny-automator' );
}
$args = array(
'post_type' => 'course',
'posts_per_page' => 999,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any course', '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__( '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_lf_courses', $option );
}