landbryo of Mission Lab
6/7/2019 - 10:01 PM

Gravity Forms Restrict Content Pro User Registration

Use this function along with the Gravity Forms User Registration add-on to add users to an RCP subscription upon registration.

function iwitness_gf_rcp_user_registration( $user_id, $feed, $entry ) {

	// retrieve subscription id from radio input
	$subscription_id = rgar( $entry, '5' );

	// create customer from $user_id
	$customer_id = rcp_add_customer( array(
		'user_id' => $user_id
	) );

	// add membership to new customer
	rcp_add_membership( array(
		'customer_id' => $customer_id,
		'object_id'   => $subscription_id,
		'status'      => 'active'
	) );

	delete_user_meta( $user_id, 'rcp_signup_subscription_id' );

}

add_action( 'gform_user_registered', 'iwitness_gf_rcp_user_registration', 10, 3 );