Filter
uncanny-automator
uap_option_get_all_plans
Filters all plans retrieved from the database, allowing modification before they are returned.
add_filter( 'uap_option_get_all_plans', $callback, 10, 1 );
Description
Filter the array of all available plans for the armember integration. Developers can use this hook to modify the plan data before it's used, for example, to add or remove plans, or alter plan properties. This filter fires when retrieving all plans.
Usage
add_filter( 'uap_option_get_all_plans', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is a mixed type that is not fully described in the provided context, but it appears to be an array of arguments or default values for retrieving membership plans.
Return Value
The filtered value.
Examples
/**
* Filter to modify the output of all available membership plans.
*
* This function demonstrates how to hook into 'uap_option_get_all_plans'
* to potentially alter the list of plans before they are used.
* For instance, you might want to exclude a specific plan from appearing
* in certain contexts or add custom data to each plan.
*
* @param array $plans An array containing all available membership plans.
* Each plan is likely an associative array with details like ID, name, price, etc.
* @return array The modified array of membership plans.
*/
function my_custom_uap_modify_all_plans( $plans ) {
// Example: If a plan with ID '5' should not be displayed, remove it.
if ( ! empty( $plans ) && is_array( $plans ) ) {
foreach ( $plans as $key => $plan ) {
if ( isset( $plan['id'] ) && $plan['id'] == 5 ) {
unset( $plans[ $key ] );
}
}
}
// Example: Add a custom attribute to each plan, indicating if it's a premium plan.
// This assumes a 'price' key exists and we're defining premium based on a threshold.
if ( ! empty( $plans ) && is_array( $plans ) ) {
foreach ( $plans as &$plan ) { // Use '&' for direct modification of the array element
if ( isset( $plan['price'] ) && (float) $plan['price'] > 100 ) {
$plan['is_premium'] = true;
} else {
$plan['is_premium'] = false;
}
}
unset( $plan ); // Unset the reference to avoid potential issues
}
// Always return the (potentially modified) array of plans.
return $plans;
}
// Add the filter to WordPress.
// The original hook likely passes the $option (which is an array of plans in this context)
// and potentially other arguments. We are assuming the hook might pass just the $option array.
// If the original hook signature were different, we'd adjust the accepted_args.
// For this example, we'll assume it passes at least the $plans array.
add_filter( 'uap_option_get_all_plans', 'my_custom_uap_modify_all_plans', 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/armember/helpers/armember-helpers.php:83
public function get_all_plans( $args = array() ) {
$defaults = array(
'option_code' => 'AR_MEMBERSHIP_PLANS',
'label' => esc_attr__( 'Membership plan', 'uncanny-automator' ),
'supports_custom_value' => false,
'is_ajax' => false,
'target_field' => null,
'endpoint' => null,
'is_any' => false,
'is_all' => false,
);
$args = wp_parse_args( $args, $defaults );
$armember_plans = $this->armember_subscription_class;
$plans = $armember_plans->arm_get_all_subscription_plans( 'arm_subscription_plan_id,arm_subscription_plan_name' );
$options = array();
foreach ( $plans as $plan_id => $plan_name ) {
if ( empty( $plan_name ) ) {
// translators: 1: Plan ID
$plan_id = sprintf( esc_attr__( 'ID: %1$s (no title)', 'uncanny-automator' ), $plan_id );
}
$options[ $plan_id ] = $plan_name['arm_subscription_plan_name'];
}
if ( true === $args['is_any'] ) {
$options = array( '-1' => esc_html__( 'Any membership', 'uncanny-automator' ) ) + $options;
}
if ( true === $args['is_all'] ) {
$options = array( '-1' => esc_html__( 'All memberships', 'uncanny-automator' ) ) + $options;
}
$option = array(
'input_type' => 'select',
'option_code' => $args['option_code'],
/* translators: HTTP request method */
'label' => $args['label'],
'required' => true,
'supports_custom_value' => $args['supports_custom_value'],
'relevant_tokens' => array(),
'options' => $options,
'options_show_id' => apply_filters( 'automator_options_show_id', true, $this ),
);
return apply_filters( 'uap_option_get_all_plans', $option );
}