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.
- $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, cancelled, 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.
Returns true if the subscription level was successfully given to the user, or false if not.
$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 );