arm_before_update_user_subscription
Fires before a user's subscription is updated, providing access to user ID and status.
add_action( 'arm_before_update_user_subscription', $callback, 10, 1 );
Description
Fires before a user's subscription is updated in ARMember. Developers can use this action to perform custom actions or modify data before the subscription update is processed, for example, logging changes or triggering external integrations. The hook passes the user ID and a placeholder parameter, '0', for potential future use.
Usage
add_action( 'arm_before_update_user_subscription', 'your_function_name', 10, 1 );
Parameters
-
$user_id(mixed) - The ID of the user whose subscription is about to be updated.
Examples
<?php
/**
* Example function to hook into 'arm_before_update_user_subscription'.
* This function demonstrates how to access and potentially modify data
* before a user's subscription is updated in the ARMember plugin.
*
* In this realistic scenario, we might want to log this event or
* trigger a specific notification *before* the subscription status changes.
*
* @param int|string $user_id The ID of the user whose subscription is being updated.
* @param mixed $extra_data An additional parameter, often used for specific context.
* In the provided source, it's '0', indicating no specific extra data.
*/
function my_custom_arm_before_subscription_update_logic( $user_id, $extra_data ) {
// Check if $extra_data is indeed '0' as per the source, or handle other possibilities.
// For demonstration, we'll assume $extra_data is relevant context.
$context_info = ( $extra_data === '0' ) ? 'No specific context provided.' : 'Context: ' . esc_html( print_r( $extra_data, true ) );
// Real-world scenario: Log the impending subscription update.
// This could be for debugging, auditing, or triggering external systems.
error_log( sprintf(
'ARMember: A subscription update is about to occur for user ID %1$d. %2$s',
$user_id,
$context_info
) );
// Another realistic scenario: Check for specific user meta before the update.
// For example, if a user has a grace period active, you might want to
// perform a different action or prevent the update under certain conditions.
$grace_period_active = get_user_meta( $user_id, 'arm_grace_period_active', true );
if ( 'yes' === $grace_period_active ) {
// In a real application, you might log this, notify the user,
// or even queue a delayed subscription update.
error_log( sprintf(
'ARMember: User ID %1$d is in their grace period. Considering special handling.',
$user_id
) );
// If you wanted to *prevent* the subscription update based on this condition,
// you might set a flag that other functions could check, or even use
// wp_die() if the action is critical and cannot proceed.
// For this example, we're just logging and letting the update proceed.
}
// If this were a filter hook, you would return the modified data here.
// For an action hook like this one, no return value is typically needed
// unless you're signaling an error or a specific outcome to other parts of the system.
}
add_action( 'arm_before_update_user_subscription', 'my_custom_arm_before_subscription_update_logic', 10, 2 );
?>
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/actions/armember-membership-plan-cancelled.php:82
uncanny-automator-pro/src/integrations/armember/actions/armember-add-to-membership-plan.php:112
protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
$plan_id = isset( $parsed[ $this->get_action_meta() ] ) ? sanitize_text_field( $parsed[ $this->get_action_meta() ] ) : '';
if ( empty( $plan_id ) ) {
$action_data['complete_with_errors'] = true;
$message = esc_html__( 'Plan does not exist.', 'uncanny-automator' );
Automator()->complete->action( $user_id, $action_data, $recipe_id, $message );
return;
}
global $arm_subscription_plans;
do_action( 'arm_before_update_user_subscription', $user_id, '0' );
$arm_subscription_plans->arm_add_membership_history( $user_id, $plan_id, 'cancel_subscription' );
do_action( 'arm_cancel_subscription', $user_id, $plan_id );
$arm_subscription_plans->arm_clear_user_plan_detail( $user_id, $plan_id );
update_user_meta( $user_id, 'arm_secondary_status', 6 );
Automator()->complete->action( $user_id, $action_data, $recipe_id );
}