Filter
uncanny-automator
uap_option_all_mp_courses
Filters the array of all MP courses, allowing modification before display or use.
add_filter( 'uap_option_all_mp_courses', $callback, 10, 1 );
Description
Filters the available options for "MemberPress Course" triggers and actions, allowing developers to modify or add new course-related token options. This hook is useful for customizing what data about MemberPress courses is available for use within Uncanny Automator recipes.
Usage
add_filter( 'uap_option_all_mp_courses', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter, `$option`, is a mixed type that likely holds or is used to construct an option or setting related to MemberPress Courses within the Uncanny Automator plugin.
Return Value
The filtered value.
Examples
<?php
/**
* Example of filtering the uap_option_all_mp_courses hook.
*
* This example demonstrates how to add additional course-related options
* to be available within the Uncanny Automator plugin when integrating with MemberPress Courses.
* It adds a new option to display the course author's username.
*/
add_filter( 'uap_option_all_mp_courses', 'my_custom_mp_course_options', 10, 1 );
function my_custom_mp_course_options( $option ) {
// Ensure the $option array has the expected structure before modifying.
if ( ! is_array( $option ) || ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
return $option;
}
// Add a new option to display the course author's username.
// We'll use a placeholder 'AUTHOR_USERNAME' which the source plugin
// would need to know how to interpret and retrieve.
$option['options']['_AUTHOR_USERNAME'] = esc_attr__( 'Course Author Username', 'uncanny-automator' );
// You could also modify existing options if needed, but this example
// focuses on adding a new one.
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/memberpress-courses/helpers/memberpress-courses-helpers.php:167
public function all_mp_courses( $label = null, $option_code = 'MPCOURSE', $any_option = true ) {
if ( ! $label ) {
$label = esc_attr__( 'Course', 'uncanny-automator' );
}
$args = array(
'post_type' => modelsCourse::$cpt,
'posts_per_page' => 9999,
'orderby' => 'title',
'order' => 'ASC',
);
$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,
'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' ),
),
'custom_value_description' => _x( 'Course ID', 'Memberpress', 'uncanny-automator' ),
);
return apply_filters( 'uap_option_all_mp_courses', $option );
}