Filter
uncanny-automator
uap_option_all_pmp_memberships
Filters the array of all Paid Memberships Pro membership levels available on the site.
add_filter( 'uap_option_all_pmp_memberships', $callback, 10, 1 );
Description
Fires when retrieving all available Paid Memberships Pro membership levels. Developers can use this filter to modify the list of membership levels returned, for example, to exclude specific levels from appearing in automations.
Usage
add_filter( 'uap_option_all_pmp_memberships', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the value being filtered, typically an array of membership levels.
Return Value
The filtered value.
Examples
/**
* Add custom subscription fields to the UAP Paid Memberships Pro options.
*
* This function hooks into 'uap_option_all_pmp_memberships' to add new
* options related to Paid Memberships Pro subscriptions for Uncanny Automator.
* It appends fields like subscription start date, end date, period, and cycle
* to the existing options array.
*
* @param array $option The original options array.
* @return array The modified options array with new subscription fields.
*/
add_filter( 'uap_option_all_pmp_memberships', function( $option ) {
// Check if the $option is an array and has the expected structure before modification.
if ( ! is_array( $option ) || ! isset( $option['paid_memberships_pro']['tokens'] ) || ! is_array( $option['paid_memberships_pro']['tokens'] ) ) {
// If the structure is unexpected, return the original option to prevent errors.
return $option;
}
// Define the new options to be added.
$new_subscription_options = array(
'UAP_PMP_SUBSCRIPTION_PERIOD' => esc_attr__( 'Subscription period', 'uncanny-automator' ),
'UAP_PMP_SUBSCRIPTION_CYCLE' => esc_attr__( 'Subscription cycle number', 'uncanny-automator' ),
'UAP_PMP_SUBSCRIPTION_START' => esc_attr__( 'Subscription start date', 'uncanny-automator' ),
'UAP_PMP_SUBSCRIPTION_END' => esc_attr__( 'Subscription end date', 'uncanny-automator' ),
);
// Merge the new options with the existing 'tokens' for Paid Memberships Pro.
$option['paid_memberships_pro']['tokens'] = array_merge(
$option['paid_memberships_pro']['tokens'],
$new_subscription_options
);
// Return the modified options array.
return $option;
}, 10, 1 ); // 10 is the default priority, 1 is the number of accepted arguments.
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/paid-memberships-pro/helpers/paid-memberships-pro-helpers.php:96
public function all_memberships( $label = null, $option_code = 'PMPMEMBERSHIP' ) {
if ( ! $label ) {
$label = esc_attr__( 'Membership', 'uncanny-automator' );
}
global $wpdb;
$qry = "SELECT * FROM $wpdb->pmpro_membership_levels ORDER BY id ASC";
// Ignored no need to escape since there are no arguments to accept.
$levels = $wpdb->get_results( $qry ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$options = array();
if ( $levels ) {
$options['-1'] = esc_attr__( 'Any membership', 'uncanny-automator' );
foreach ( $levels as $level ) {
$options[ $level->id ] = $level->name;
}
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Membership title', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr__( 'Membership ID', 'uncanny-automator' ),
$option_code . '_USER_ID' => esc_attr__( 'User ID', 'uncanny-automator' ),
$option_code . '_DISCOUNT_CODE' => esc_attr__( 'Discount code', 'uncanny-automator' ),
$option_code . '_DISCOUNT_CODE_ID' => esc_attr__( 'Discount code ID', 'uncanny-automator' ),
$option_code . '_INITIAL_AMOUNT' => esc_attr__( 'Initial amount', 'uncanny-automator' ),
$option_code . '_SUBSCRIPTION_ID' => esc_attr__( 'Subscription ID', 'uncanny-automator' ),
$option_code . '_SUBSCRIPTION_AMOUNT' => esc_attr__( 'Subscription amount', 'uncanny-automator' ),
$option_code . '_SUBSCRIPTION_PERIOD' => esc_attr__( 'Subscription period', 'uncanny-automator' ),
$option_code . '_SUBSCRIPTION_CYCLE' => esc_attr__( 'Subscription cycle number', 'uncanny-automator' ),
$option_code . '_SUBSCRIPTION_START' => esc_attr__( 'Subscription start date', 'uncanny-automator' ),
$option_code . '_SUBSCRIPTION_END' => esc_attr__( 'Subscription end date', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_all_pmp_memberships', $option );
}