rcp_set_status

This action has been deprecated. Use rcp_transition_membership_status instead.

Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.

If you need assistance with this, please reach out to our list of consultants for further assistance:
https://codeable.io/developers/restrict-content-pro/

This action is triggered whenever a user's status (pending, free, active, expired, canceled) is set.

Parameters:

  • $new_status - Name of the new status being set (pending, free, active, expired, canceled).
  • $user_id - ID of the user whose status is being changed.
  • $old_status - The member's previous status before this change.
  • $member - The RCP_Member object for this user.

Similar Actions:

RCP also has a dynamic action that is fired at the same time: rcp_set_status_{$new_status}. This action is exactly the same, but the $new_status variable is included in the status name instead of as a parameter. Here are two examples that achieve the same result:

function ag_rcp_set_status( $new_status, $user_id, $old_status, $member ) {
    if ( 'active' == $new_status ) {
        // Your custom code in here to be run when status is set to 'active'.
    }
}

add_action( 'rcp_set_status', 'ag_rcp_set_status', 10, 4 );
function ag_rcp_set_status_active( $user_id, $old_status, $member ) {
    // Your custom code in here to be run when status is set to 'active'.
}

add_action( 'rcp_set_status_active', 'ag_rcp_set_status_active', 10, 3 );

rcp_set_status_active is a good action to use if you need to trigger some code immediately after a subscription is activated. But note this action may also run after renewals and upgrades, so if you only want your code triggered once, it's helpful to set a piece of user meta to indicate that your action has already been completed. For example:

function ag_rcp_set_status_active( $user_id, $old_status, $member ) {
    $has_completed = get_user_meta( $user_id, 'rcp_has_completed_some_custom_action', true );

    if ( $has_completed ) {
        // We've already done this for this user! Bail!
        return;
    }

    // Insert your custom code here.

    // Now set the flag so we don't run it again.
    update_user_meta( $user_id, 'rcp_has_completed_some_custom_action', true );
}

add_action( 'rcp_set_status_active', 'ag_rcp_set_status_active', 10, 3 );
Powered by Zendesk