Restrict Content Pro

rcp_add_user_to_subscription()

Coming soon: Restrict Content Pro is becoming Kadence Memberships. You may see both names used while we update the product, documentation, and customer experience.

Note: This content is provided as a resource within our developer documentation. Because custom code requires highly specific implementation, we encourage you to work with a qualified developer if you need guidance. You can find our recommended consultants here: https://codeable.io/developers/restrict-content-pro

Programmatically assigns a WordPress user a membership level: creates an RCP customer if needed, then adds or renews a membership record.

Deprecated in 3.0. Prefer rcp_add_membership() or RCP_Customer::add_membership() for new code.

If the customer already has the same level, the existing membership is renewed instead of creating a duplicate. Fires rcp_successful_registration on success.

Parameters

$user_id (int) – WordPress user ID.

$args (array) – Membership arguments. Only subscription_id (membership level ID) is required.

  • status (string) – Optional. active, cancelled, expired, or legacy free (treated as active). Default: calculated from level.
  • subscription_id (int) – Required. Membership level ID.
  • expiration (string) – Optional. MySQL datetime. Calculated if omitted.
  • discount_code (string) – Optional. Records usage and increments the code count.
  • subscription_key (string) – Optional.
  • trial_duration (int|bool) – Optional. Sets trialing when provided.
  • trial_duration_unit (string) – Optional. day, month, or year. Default: day.
  • recurring (bool) – Optional. Sets auto_renew. Default: false.
  • payment_profile_id (string) – Optional. Gateway subscription / profile ID.

Return values

(bool) – true on success; false if the level ID is missing, invalid, or membership creation fails.

Examples

$added = rcp_add_user_to_subscription(
	$user_id,
	array(
		'subscription_id' => 2,
		'status'          => 'active',
	)
);
$customer = rcp_get_customer_by_user_id( $user_id );
if ( $customer ) {
	rcp_add_membership(
		array(
			'customer_id' => $customer->get_id(),
			'object_id'   => 2,
			'status'      => 'active',
		)
	);
}

Related: How-to Manually Add a New Membership.

Last updated: October 16, 2026
Was this page helpful?
Thanks for the feedback!