rcp_add_user_to_subscription()

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 function is deprecated. Use rcp_add_membership() instead.

rcp_add_user_to_subscription( $user_id, $args = array() )

This function can be used to add a user to a subscription level. Note that it does not connect to a payment gateway or take payment; it just assigns the membership level, status, expiration date and other data within Restrict Content Pro.

Parameters:

  • $user_id (int) - ID of the user to add to the subscription level.
  • $args (array) - Array of arguments:
    • subscription_id (int) - Required. ID of the subscription level to assign to the user. This is the only required argument.
    • status (string) - Optional. Status to set: free, active, canceled, or expired. If omitted, the status will automatically be assigned to "free" or "active", depending on the chosen subscription level.
    • expiration (string) - Optional. Expiration date to give the user in MySQL format. If omitted, the expiration date is calculated automatically based on the subscription level duration.
    • discount_code (string) - Optional. Name of a discount code to add to the user's profile and increment usage count.
    • subscription_key (string) - Optional. Subscription key to add to the user's profile.
    • trial_duration (int|bool) - Optional. Only supply this to give the user a free trial.
    • trial_duration_unit (string) - Optional. "day", "month", or "year". Default is "day".
    • recurring (bool) - Optional. Whether or not the user has a recurring subscription. Default is false. 
    • payment_profile_id (string) - Optional. Payment profile ID with the gateway to add to the member's RCP profile.

Return values:

Returns true if the subscription level was successfully given to the user, or false if not.

Example usage:

$user_id = 123;

$args = array(
    'subscription_id'    => 3,
    'status'             => 'active',
    'expiration'         => date( 'Y-m-d 23:59:59', strtotime( '+1 month', current_time( 'timestamp' ) ) ),
    'discount_code'      => 'free_subscription'
);

rcp_add_user_to_subscription( $user_id, $args );
Have more questions? Submit a request