Restrict Content Pro
rcp_add_membership()
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
Creates a new membership record in the database. Requires Restrict Content Pro 3.0 or later.
Use this for custom signup flows, imports, or admin automation. After creation, you may need to call RCP_Membership::activate() for active memberships so roles and welcome emails run as expected. To change an existing record, use rcp_update_membership() or methods on the RCP_Membership object.
Parameters
$data (array) — Membership data. Keys include:
Required
customer_id (int) — RCP_Customer ID this membership belongs to.
Commonly used
object_id (int) — Membership level ID. Must match a valid membership level; creation fails if the level cannot be loaded.object_type (string) — Object type. DefaultÂmembership.status (string) —Âpending,Âactive,Âcancelled, orÂexpired. DefaultÂpending. (LegacyÂfree is converted toÂactive.)signup_method (string) —Âlive,Âmanual, orÂimported. DefaultÂlive.
Amounts and billing
currency (string) — Default is the site currency fromÂrcp_get_currency().initial_amount (string) — Initial charge. If omitted, RCP derives it from the membership level.recurring_amount (string) — Renewal amount. If omitted, RCP derives it from the level.auto_renew (bool) — Whether auto-renew is enabled. DefaultÂfalse.times_billed (int) — Times billed so far. DefaultÂ0.maximum_renewals (int) — Payment plan renewal cap (0 = unlimited). DefaultÂ0.
Dates
created_date (string) — MySQL datetime. Default current time.trial_end_date (string) — Trial end; may be set automatically when the customer is trial-eligible and the level allows trials.renewed_date (string) — Last renewal date.cancellation_date (string) — Cancellation date.expiration_date (string) — Expiration or next renewal. Leave empty to auto-calculate from the level (and upgrade context). UseÂnone for no expiration (stored as lifetime / null).
Gateway
gateway (string) — Gateway slug.gateway_customer_id (string) — Gateway customer ID (for example StripeÂcus_…).gateway_subscription_id (string) — Gateway subscription ID (for example StripeÂsub_…).subscription_key (string) — Unique key; generated if omitted when saved via membership methods.
Other
user_id (int|null) — WordPress user ID; backfilled from the customer when omitted.upgraded_from (int) — Membership ID this one was upgraded from.notes (string) — Notes on the membership. Prefer RCP_Membership::add_note() to append notes later.disabled (int) —Â0 enabled,Â1 disabled (soft-deleted). DefaultÂ0.
Return values
int|false — New membership ID on success, or false on failure (missing customer_id, invalid level, or database error).
Examples
Create an active membership for customer #50 on level #2:
$membership_id = rcp_add_membership( array(
'customer_id' => 50,
'object_id' => 2,
'status' => 'active',
) );
if ( $membership_id ) {
$membership = rcp_get_membership( $membership_id );
$membership->activate();
}
Manual admin grant with explicit expiration:
$membership_id = rcp_add_membership( array(
'customer_id' => 50,
'object_id' => 2,
'status' => 'active',
'signup_method' => 'manual',
'expiration_date' => '2026-12-31 23:59:59',
) );