Filter
uncanny-automator-pro
automator_mepr_subscr_id
Filters the MemberPress subscription ID used in automator integrations, allowing modification before it's applied.
add_filter( 'automator_mepr_subscr_id', $callback, 10, 1 );
Description
Fires when generating a unique subscription ID for new MemberPress subscriptions created by Uncanny Automator. Developers can filter this ID to use custom prefixes or generate IDs differently, ensuring uniqueness before saving. The original ID is a prefixed unique string.
Usage
add_filter( 'automator_mepr_subscr_id', 'your_function_name', 10, 1 );
Parameters
-
$product_id(mixed) - This parameter is used to dynamically generate a unique subscription ID for a MemberPress subscription.
Return Value
The filtered value.
Examples
<?php
/**
* Example filter to modify the MemberPress subscription ID.
*
* This filter allows you to prepend a custom prefix or modify the
* auto-generated subscription ID based on specific conditions.
*
* @param string $subscription_id The default subscription ID ('ua-ts_' . uniqid()).
* @param int $product_id The ID of the MemberPress product.
*
* @return string The modified subscription ID.
*/
add_filter( 'automator_mepr_subscr_id', 'my_custom_mepr_subscription_id', 10, 2 );
function my_custom_mepr_subscription_id( $subscription_id, $product_id ) {
// Example: If the product ID is 123, prepend 'special-' to the subscription ID.
if ( $product_id == 123 ) {
return 'special-' . $subscription_id;
}
// Example: If you want to ensure a certain format, you could re-generate or re-format.
// For demonstration, let's just add the product ID to the end.
return $subscription_id . '_' . $product_id;
}
?>
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/actions/mp-addusermembership.php:181
$sub = false;
// Check if it is not a one-time payment.
if ( ! $product->is_one_time_payment() ) {
$sub = new MeprSubscription();
$sub->user_id = $user->ID;
$sub->subscr_id = apply_filters( 'automator_mepr_subscr_id', 'ua-ts_' . uniqid(), $product_id );
$sub->product_id = $product_id;
$sub->price = isset( $sub_total ) ? MeprUtils::format_currency_us_float( $sub_total ) : MeprUtils::format_currency_us_float( $product->price );
$sub->period = $product->period;
$sub->period_type = (string) $product->period_type;
$sub->limit_cycles = $product->limit_cycles;
$sub->limit_cycles_num = (int) $product->limit_cycles_num;
$sub->limit_cycles_action = $product->limit_cycles_action;