Filter
uncanny-automator
uap_option_all_wplms_courses
Filters the options for all WPLMS courses, allowing modification before they are retrieved.
add_filter( 'uap_option_all_wplms_courses', $callback, 10, 1 );
Description
This filter hook `uap_option_all_wplms_courses` allows developers to modify the array of WPLMS course options before they are presented. It fires when Uncanny Automator retrieves WPLMS course data. Developers can add, remove, or alter course fields available for use in automations.
Usage
add_filter( 'uap_option_all_wplms_courses', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is a placeholder for the label that will be displayed for the course option.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Add custom WPLMS course information to the automator options.
*
* This example demonstrates how to hook into 'uap_option_all_wplms_courses'
* to add new options related to WPLMS course meta data that the Uncanny Automator
* plugin can use.
*
* @param array $option The original array of WPLMS course options.
* @return array The modified array of WPLMS course options, including new custom fields.
*/
function my_custom_wplms_course_options( $option ) {
// Assuming $option is an array structured similarly to what's in the source context.
// Let's say we want to add the course instructor's display name and email.
// We'll need to assume that the $option array has a structure that allows us
// to append new key-value pairs.
// In a real scenario, you'd likely fetch actual course data and process it.
// For this example, we'll simulate adding new option codes.
// A common pattern is to use a prefix, e.g., 'custom_'.
// Let's assume the $option array has a structure like:
// $option = [
// 'wplms_courses' => [
// 'label' => 'WPLMS Courses',
// 'options' => [
// 'course_id' => 'Course ID',
// // ... other course options
// ],
// ],
// ];
// We need to find the correct section to append to.
// Based on the hook name 'uap_option_all_wplms_courses', it's likely
// related to an array of courses. Let's assume the structure involves
// a key like 'wplms_courses' which contains an 'options' array.
if ( isset( $option['wplms_courses']['options'] ) && is_array( $option['wplms_courses']['options'] ) ) {
// Add a custom option for the Course Instructor Display Name.
// We'll use a hypothetical option code 'COURSE_INSTRUCTOR_NAME'.
$option['wplms_courses']['options']['COURSE_INSTRUCTOR_NAME'] = esc_attr__( 'Course Instructor Name', 'my-text-domain' );
// Add a custom option for the Course Instructor Email.
// We'll use a hypothetical option code 'COURSE_INSTRUCTOR_EMAIL'.
$option['wplms_courses']['options']['COURSE_INSTRUCTOR_EMAIL'] = esc_attr__( 'Course Instructor Email', 'my-text-domain' );
// You might also want to add a general option for all courses if the structure allows.
// For example, if there's a 'course_list' key.
// if ( isset( $option['course_list'] ) && is_array( $option['course_list'] ) ) {
// $option['course_list']['MY_CUSTOM_COURSE_FIELD'] = esc_attr__( 'My Custom Course Field', 'my-text-domain' );
// }
}
// Return the modified array, which will be used by Uncanny Automator.
return $option;
}
// Add the filter to WordPress.
// The second parameter (10) is the priority, and the third parameter (1)
// indicates that our callback function accepts one argument.
add_filter( 'uap_option_all_wplms_courses', 'my_custom_wplms_course_options', 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/wplms/helpers/wplms-helpers.php:134
public function all_wplms_courses( $label = null, $option_code = 'WPLMS_COURSE', $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_wplms_courses', $option );
}