Gravity Forms User Registration After the Fact

Gravity Forms lets you set up user registration via an additional plugin but it require some setup. It’s not hard to run into a scenario where you though people were getting registered but they were not. Not a big deal if it’s a handful of people but not pleasant if it’s more than that.

I wrote this little plugin the other night to deal with a scenario like this. The comments below explain most of the important bits. It will require you to know what your form ID is, the form field IDs, and the blog ID of the site you want to add the users to.

I trigger the function by attaching it to a shortcode and sticking that shortcode in a post or page. I’m not sure that’s the best idea but it seems to work fine.


<?php 
/*
Plugin Name: turn back time user maker
Plugin URI: https://github.com/woodwardtw/
Description: 
Author: Tom Woodward
Version: 1.5
Author URI: http://bionicteaching.com/
*/

//gravity form fetch
function make_users_now(){					    
					$search_criteria = array();
					$sorting = array();
					$paging = array( 'offset' => 0, 'page_size' => 100 );//set to deal with up to 100 entries

					  $entries  = GFAPI::get_entries( 1, $search_criteria, $sorting, $paging  );//the first number is the form you're referencing

					  if ( !empty($entries) ){
					        foreach ($entries as $entry) {  
						        $user_name = $entry['2'];//match these up with the fields in your form
						        $password = $entry['4'];
						        $email = $entry['3'];
								
								//make the user if their email isn't already there

								if ( !email_exists( $email ) ){
									$user_id = wpmu_create_user($user_name, $password, $email);
								}

								//add the user to the ddp site
								add_user_to_blog(19, $user_id, 'author');//make the first number (19) match blog you want to add them to

						}
					}
				}

add_shortcode( 'makeusersnow', 'make_users_now' );//stick this shortcode on a page and visit the page to trigger this

Comments on this post

No comments.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL