Filter
uncanny-automator-pro
uap_option_get_all_mp_quiz
Filters the MemberPress Courses quiz options before they are retrieved.
add_filter( 'uap_option_get_all_mp_quiz', $callback, 10, 1 );
Description
Filters the options array for MemberPress Quizzes used in Uncanny Automator. Developers can modify the quiz ID selection or add custom logic when retrieving available quizzes for automations.
Usage
add_filter( 'uap_option_get_all_mp_quiz', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the value of the option being filtered, which is expected to be an array of MemberPress quizzes.
Return Value
The filtered value.
Examples
// Example: Add a custom option to the MemberPress Quiz selection if a specific user role is present.
add_filter( 'uap_option_get_all_mp_quiz', 'my_custom_mp_quiz_options', 10, 1 );
function my_custom_mp_quiz_options( $option ) {
// Check if the current user has a specific role (e.g., 'administrator')
if ( current_user_can( 'administrator' ) ) {
// Add a new option to the existing $options array.
// This is a hypothetical scenario where you might want to offer a "Manual Selection" option
// for administrators that bypasses the dynamic fetching of MemberPress quizzes.
$option['options']['manual_select'] = array(
'value' => 'manual',
'label' => __( 'Manual Quiz Selection', 'uncanny-automator-pro' ),
);
}
// Return the modified option array.
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
uncanny-automator-pro/src/integrations/memberpress-courses/helpers/memberpress-courses-pro-helpers.php:77
public function get_all_mp_quiz( $label = null, $option_code = 'MPC_QUIZ', $args = array() ) {
if ( ! $label ) {
$label = esc_attr__( 'Quiz', 'uncanny-automator-pro' );
}
$args = wp_parse_args(
$args,
array(
'uo_include_any' => false,
'uo_any_label' => esc_attr__( 'Any quiz', 'uncanny-automator-pro' ),
)
);
$query_args = array(
'post_type' => 'mpcs-quiz',
'posts_per_page' => 999,
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->wp_query( $query_args, $args['uo_include_any'], $args['uo_any_label'] );
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(),
'custom_value_description' => _x( 'Quiz ID', 'Memberpress', 'uncanny-automator-pro' ),
);
return apply_filters( 'uap_option_get_all_mp_quiz', $option );
}