Filter
uncanny-automator-pro
uap_option_get_all_thrive_quizzes
Filters Thrive Quiz plugin settings before they are saved or retrieved, allowing for modifications.
add_filter( 'uap_option_get_all_thrive_quizzes', $callback, 10, 1 );
Description
Fires when Uncanny Automator retrieves Thrive Quizzes for a MemberPress integration. Developers can filter the returned `$option` array to modify the list of available Thrive Quizzes or add custom options. This hook is useful for advanced customization or to exclude specific quizzes from being selectable in automations.
Usage
add_filter( 'uap_option_get_all_thrive_quizzes', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the Thrive Quiz options that are being retrieved.
Return Value
The filtered value.
Examples
/**
* Example of filtering the Thrive Quizzes available in Uncanny Automator Pro.
*
* This function demonstrates how to add custom logic to filter the list of
* Thrive Quizzes that are available for selection within Uncanny Automator Pro's
* triggers and actions.
*
* @param array $thrive_quizzes An array of Thrive Quiz data, typically containing
* 'value' (quiz ID) and 'label' (quiz title).
*
* @return array The filtered array of Thrive Quizzes.
*/
add_filter( 'uap_option_get_all_thrive_quizzes', 'my_custom_filter_thrive_quizzes', 10, 1 );
function my_custom_filter_thrive_quizzes( $thrive_quizzes ) {
// If you want to exclude a specific Thrive Quiz by its ID:
$quiz_id_to_exclude = 123; // Replace with the actual ID of the quiz to exclude.
if ( ! empty( $thrive_quizzes ) && is_array( $thrive_quizzes ) ) {
$filtered_quizzes = array_filter( $thrive_quizzes, function( $quiz ) use ( $quiz_id_to_exclude ) {
// Ensure the quiz has a 'value' key and it's not the one we want to exclude.
return isset( $quiz['value'] ) && $quiz['value'] != $quiz_id_to_exclude;
} );
// If you want to add a new, custom quiz option (less common for this specific filter,
// as it's typically meant to *filter* existing ones, but possible):
// $filtered_quizzes[] = array(
// 'value' => 'my_custom_quiz_id',
// 'label' => 'My Custom Quiz (Not from Thrive)',
// );
return $filtered_quizzes;
}
// If the input is not an array or is empty, return it as is.
return $thrive_quizzes;
}
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/helpers/memberpress-pro-helpers.php:316
public function get_all_mp_coupons( $args = array() ) {
$defaults = array(
'option_code' => 'MP_COUPONS',
'label' => esc_attr__( 'Coupon', 'uncanny-automator-pro' ),
'is_any' => false,
'is_all' => false,
'supports_custom_value' => false,
);
$args = wp_parse_args( $args, $defaults );
$query_args = array(
//phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
'posts_per_page' => apply_filters( 'automator_select_all_posts_limit', 999, 'memberpresscoupon' ),
'orderby' => 'title',
'order' => 'DESC',
'post_type' => 'memberpresscoupon',
'post_status' => 'publish',
);
$mp_coupons = Automator()->helpers->recipe->options->wp_query( $query_args );
if ( true === $args['is_any'] ) {
$mp_coupons = array( '-1' => __( 'Any coupon', 'uncanny-automator-pro' ) ) + $mp_coupons;
}
if ( true === $args['is_all'] ) {
$mp_coupons = array( '-1' => __( 'All coupons', 'uncanny-automator-pro' ) ) + $mp_coupons;
}
$relevant_tokens = array(
'MPPRODUCT' => esc_attr__( 'Product title', 'uncanny-automator-pro' ),
'MPPRODUCT_ID' => esc_attr__( 'Product ID', 'uncanny-automator-pro' ),
'MPPRODUCT_URL' => esc_attr__( 'Product URL', 'uncanny-automator-pro' ),
'MPPRODUCT_THUMB_ID' => esc_attr__( 'Product featured image ID', 'uncanny-automator-pro' ),
'MPPRODUCT_THUMB_URL' => esc_attr__( 'Product featured image URL', 'uncanny-automator-pro' ),
'MP_COUPON' => esc_attr__( 'Coupon code', 'uncanny-automator-pro' ),
'MP_COUPON_TYPE' => esc_attr__( 'Coupon type', 'uncanny-automator-pro' ),
'MP_COUPON_AMOUNT' => esc_attr__( 'Coupon amount', 'uncanny-automator-pro' ),
);
$option = array(
'option_code' => $args['option_code'],
'label' => $args['label'],
'input_type' => 'select',
'required' => true,
'options_show_id' => false,
'relevant_tokens' => $relevant_tokens,
'options' => $mp_coupons,
'supports_custom_value' => $args['supports_custom_value'],
);
return apply_filters( 'uap_option_get_all_thrive_quizzes', $option );
}