Gravity Forms and MemberPress are paid plugins which solve very different problems. Both are developer friendly and extendible. The following is some custom code which runs after Gravity Forms creates a subscriber account and assigns it with a predefined MemberPress membership.
// Hook into Gravity Forms User Registration. Runs after user has been registered
add_action( 'gform_user_registered', 'memberpress_membership_account_prep', 10, 4);
// Setup lifetime MemberPress membership
function memberpress_membership_account_prep( $user_id, $feed, $entry ) {
$url = rest_url( 'mp/v1/transactions' );
$headers = [ 'Authorization' => 'Basic AUTH_KEY_HERE' ];
$data = [
'member' => $user_id,
'amount' => "0.00",
'total' => "0.00",
'membership' => "1234", # MemberPress membership ID here
'status' => "complete",
'gateway' => "manual",
'expires_at' => "0000-00-00 00:00:00"
];
$response = wp_remote_post( $url, [
'method' => 'POST',
'headers' => $headers,
'body' => $data
] );
}
Run Custom Code Using a Gravity Forms Hook
This code is triggered by a Gravity Forms hook to run custom code over the MemberPress’ REST API. The MemberPress REST API is not enabled by default. To use it, you first need to activate the Developer Tools add-on.
After it’s enabled, you can see the documentation on MemberPress REST API from the WordPress backend: /wp-admin/admin.php?page=memberpress-developer-tools
.
Gravity Forms Handles the User Creation
With the User Registration add-on active, Gravity Forms can be configured to create a user based on the form submission. The form I’m using asks for a name, email and username. With that information, Gravity Form generates a subscriber account and sends login details to the new user.