function ml_add_rcp_customer_membership( $user_id, $feed, $entry ) {
if ( empty( $user_id ) ) {
return;
}
/**
* We can either get a form field value,
* or hard code the level
*/
// $rcp_level = 1;
$rcp_level = rgar( $entry, '2' );
/**
* Create RCP customer
* https://docs.restrictcontentpro.com/article/2105-rcp-add-customer
*/
$customer_id = rcp_add_customer( array(
'user_id' => $user_id,
) );
/**
* Create RCP membership
* https://docs.restrictcontentpro.com/article/2082-rcp-add-membership
*/
$membership_id = rcp_add_membership( [
'customer_id' => $customer_id,
'object_id' => $rcp_level
]
);
}
add_action( 'gform_user_registered', 'ml_add_rcp_customer_membership', 10, 3 );