Integrating New Blog Templates with Gravity Forms

I decided to use Gravity forms and the "User Registration Add On" to create new sites in my multisite network instead of the default wp-signup.php page that WordPress creates. This works great so far. It gives me much more control over the fields as well as the ability to embed the form on any page.

Here's my dilemma though:

I'm unable to show the templates I've created in New Blog Templates. Is there a way to integrate this? Or is there any other solutions you can think of?

Selecting a template on my network is definitely a necessity...

  • Vinod Dalvi
    • WP Unicorn

    Hi @timstrifler,

    I hope you are well today and thank you for your question.

    I'm unable to show the templates I've created in New Blog Templates. Is there a way to integrate this? Or is there any other solutions you can think of?

    Does it work well by deactivating Gravity forms plugin?

    Best Regards,

  • timstrifler
    • The Incredible Code Injector

    Sorry, maybe I should have been more clear. New Blog Templates is working fine. However, New Blog Templates is designed so that the user can choose a template on wp-signup.php when they sign up for a multisite. I'm using Gravity forms for the multisite signup, instead of the built in sign up form on wp-signup.php. I'm wondering if there's a way to have the templates set up in New Blog Templates to show up on my gravity form.

    Is this at all possible?

  • Vinod Dalvi
    • WP Unicorn

    Hi @timstrifler,

    Thanks for your reply and more clear explanation.

    I understood your point that you are using Gravity Forms' User Registration to let users signup to create a new account and you want to let them choose Blog Template to create a new blog.

    Unfortunately it's not possible out of the box without doing a lot of customization. I have moved this over to the features & feedback section. This way it can be considered for future development, and we can also see what other community members think about the feature request.

    If you want it in urgent then you may want to post a job on the WPMU DEV job board here https://premium.wpmudev.org/wpmu-jobs/

    Cheers.

  • Vinod Dalvi
    • WP Unicorn

    Hi @josh,

    This feature may be added in future version of plugin but We don't publish ETAs to prevent disappointment if a deadline is missed(which in plugin development quite a frequent occurrence!).

    Thank you for being a WPMU DEV member and have a great day!

    Cheers,
    Vinod Dalvi

  • Tyler Postle
    • CGO

    @ignacio @Vinod Dalvi +1 for Grav form integration!

    However, with Pro-Sites 3.5 coming out soon it will be interesting to see how it all works. If Pro-Sites 3.5 registration/checkout ends up being as good as it looks like it will be then I probably won't use gravity forms for registration.

  • Ignacio
    • HummingBird

    Hi there.

    I've been working on this during the last 2 days and as I see, right now I cannot hook New Blog Templates on Gravity Forms. GF overrides all the metadata that New Blog Templates pass to WordPress when it creates a new site.

    I have submitted a ticket to Gravity Forms asking for a couple of changes.

    Sorry for that.

    Regards.
    Ignacio.

  • webatonic1
    • Site Builder, Child of Zeus

    Awesome, im really looking forward to this integration, this would make ProSites blog templates so much more flexible,

    it would be nice to have a similar blog template selection/preview process using gravity forms.

    Cant wait @Ignacio

  • webatonic1
    • Site Builder, Child of Zeus

    User Registration Add-On v1.8
    -----------------------------------------------

    Added more debug statements for logging.

    Added logging support and some initial debug statements.

    Updated two strings in activate.php to match their equivalents in wp-activate.php (as of WP 1.8.1).

    Updated signup activation to check if email address is already in use and return a message indicating such.

    Updated all places where RGUserUpgrade class was manually included to use new GFUser::include_upgrade_library() method.

    Fixed notice with missing variable $set_post_author.

    Fixed issue on single site installs where activation email title and from name
    defaulted to "WordPress".

    Fixed issue on Update form where pre-population didn't always work when a value was set to zero.

    Fixed issue where RGUserUpgrade class was called but not included.

    Fixed issue where single column list fields were not updating correctly on Update feeds.

    Fixed issue where deprecated functions were used in activation process.

    Fixed issue in Update feed on multi-site where email address said to already be used.

  • Ignacio
    • HummingBird

    They told me that latest version was a maintenance one (strange, as it's called 1.8 and not 1.8.1 or similar) so they will include the filter in the next main release.

    The filter would allow me to add some metadata when the blog is created, the blog template ID in this case. I cannot insert that meta unless they add that filter.

    Here's my message to GF Support:

    The filter is simple: In userregistration.php, line 2148, the plugin signs up the new blog but it's impossible right now to alter the signup metadata. In line 2143 there's a sentence like this:

    $meta = array('lead_id' => $entry['id'], 'user_login' => $user_data['user_login'], 'email' => $user_data['user_email']);

    A new filter (2, indeed, one for blogs another for users) would be needed there in order to integrate GF with other plugins. Just like this:

    $meta = array('lead_id' => $entry['id'], 'user_login' => $user_data['user_login'], 'email' => $user_data['user_email']);
    $ms_options = rgars($config, 'meta/multisite_options');
    
    // save current user details in wp_signups for future activation
    if(is_multisite() && $ms_options['create_site'] && $site_data = self::get_site_data($entry, $form, $config)) {
    $meta = apply_filters( 'gform_signup_blog_meta', $meta, $site_data );
    wpmu_signup_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_data['user_login'], $user_data['user_email'], $meta);
    } else {
    // wpmu_signup_user() does the following sanitization of the user_login before saving it to the database,
    // we can run this same code here to allow successful retrievel of the activation_key without actually
    // changing the user name when it is activated. 'd smith' => 'dsmith', but when activated, username is 'd smith'.
    $user_data['user_login'] = preg_replace( '/\s+/', '', sanitize_user( $user_data['user_login'], true ) );
    self::log_debug("Calling wpmu_signup_user (sends email with activation link) with login: " . $user_data['user_login'] . " email: " . $user_data['user_email'] . " meta: " . print_r($meta, true));
    $meta = apply_filters( 'gform_signup_blog_meta', $meta, $user_data );
    wpmu_signup_user($user_data['user_login'], $user_data['user_email'], $meta);
    self::log_debug("Done with wpmu_signup_user");
    }
  • webatonic1
    • Site Builder, Child of Zeus

    @Ignacio @TyePo ....Here is the Reply

    Chris replied
    Apr 4 8:08pm
    We don't have any plans currently to add that filter, but I will add it to our list of requested features. Thank you for the suggestion.

    __________________________________________

    Chris Hajer
    Gravity Forms Support Specialist

  • Tyler Postle
    • CGO

    We don't have any plans currently to add that filter, but I will add it to our list of requested features. Thank you for the suggestion.

    That is why I haven't bought it yet haha. Never know if they'll actually add it or not. I'll send them a ticket too saying that once it's added, I'll upgrade.

  • webatonic1
    • Site Builder, Child of Zeus

    Got another response today

    Yevgeny,

    Just to update you, the development team are currently working on migrating the User Registration add-on over to the new add-on framework which was included in Gravity Forms 1.8 and this feature is down for inclusion in the framework version.

    Regards,

    __________________________________________

    Richard Wawrzyniak
    Gravity Forms
    http://www.gravityforms.com

  • webatonic1
    • Site Builder, Child of Zeus

    hahaha, this integration can prove to be very powerful, since you can make fairly elaborate forms and checkout process.

    @Ignacio, when they finally add the filter, how are you visualizing the Gravity Forms/Blog Templates to look like. Will the Gravity Form have an option to select and filter various templates, perhaps showing templates by category or show all templates. Will it have images to click to see the demo and select the template, plus show the description.

    How will it work?

  • Ignacio
    • HummingBird

    Yes, exactly the same than in the default view. You can test it (but the selection won't be applied uncommenting the last lines of blogtemplates/blogtemplatesfiles/integration.php (There's a section called "GRAVITY FORMS" at the end of the file that is commented)

  • Ignacio
    • HummingBird

    Bad news: We don't need GF to be updated but GF User Registration Add-on. I'll show you where do we need that filter: In file plugins/gravityformsuserregistration/userregistration.php line 2143 there's a sentence like this:

    $meta = array('lead_id' => $entry['id'], 'user_login' => $user_data['user_login'], 'email' => $user_data['user_email']);

    we need to be able to change that array and its values if we want to set a template ID. You can do it manually by adding a new key called 'blog_template' like this:

    $meta = array('lead_id' => $entry['id'], 'user_login' => $user_data['user_login'], 'email' => $user_data['user_email'], 'blog_template' => 1);

    That way every new site will be created with template 1. The worst thing about it is that users cannot select a template with this method so we cannot change it dinamically so we need a new version of the add-on.

    Regards.
    Ignacio.

  • PC
    • WPMU DEV Initiate

    Hey there,

    I will also be interested to see what they say.

    I'm sure it will be something along the lines of "We have made note of it for a future update"...

    :slight_smile:

    If they do it, I am sure they will get a lot of signups just due to New Blog Templates and the integration features !

    Cheers, PC

  • webatonic1
    • Site Builder, Child of Zeus

    Got a reply and its not "We have made note of it for a future update"...

    -----------------------------------------------------------------------------------
    I've added a new filter to accommodate this request:

    add_filter( 'gform_user_registration_signup_meta', 'add_blog_template', 10, 4 );
    function add_blog_template( $signup_meta, $form, $entry, $feed ) {
    $signup_meta['blog_template'] = 1;
    return $signup_meta;
    }

    Attached is the latest version of the add-on. Let me know if you run into any issues with this new filter. :slight_smile:

    https://www.dropbox.com/s/ufemkvj8yn71x2o/gravityformsuserregistration_1.8.5.zip

    Best,

  • Ignacio
    • HummingBird

    Hi there.

    I'm sorry, but something has changed in the Add-on. I tested the previous version by adding that hook myself and it worked, the blog was added to the signup table. Now the site is directly created and, know what? We need a hook to change the meta too!

    If you open plugins/gravityformsuserregistration/userregistration.php (1.8.5 version) file, around line 2033 you'll see the following line:

    $blog_id = wpmu_create_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_id , array( 'public' => 1 ), $current_site->id);

    This is the meta values passed to the function: array( 'public' => 1 ) and we need to make changes to that array so we need to ask for another filter. Sorry guys :slight_frown:.

    But, meanwhile we can make it work with a little hack:

    Just change that code for this one:

    $meta = apply_filters( 'gform_site_registration_signup_meta', array( 'public' => 1 ), $form, $config );
            $blog_id = wpmu_create_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_id , $meta, $current_site->id);

    And then replace the integration.php file in NBT plugin for the attached one.

    Now you need to follow these steps in order to make it work:

    1. Once you have followed these steps: http://www.gravityhelp.com/documentation/page/User_Registration_Add-On#Setup_the_User_Registration_Add-On you should have created a new registration form and a User Registration feed.

    2. Now add two more fields to that form: Username and Site Title (both required) using the Single Line Text field type in Gravity Forms.

    3. Go to User Registration>Feed that you created. You need to set the options like the attached image (chec the New Blog Templates option and Create Site option, then map the Site Name/Site Domain fields).

    That should make the plugin work. You should see a template selector in your GF registration page.

    Now, we need to ask for a new filter there as I put in the code so please, the more of us ask for that, the sooner they'll add it.

    Just test the code and tell me if everything works for you.

    Regards.
    Ignacio.

  • webatonic1
    • Site Builder, Child of Zeus

    @Ignacio, is it possible to have a dropdown of templates in GF narrowed down to a specific template category. For instance..create a user registration form where users can only choose Magazine style templates, this can be used for a landing page for people who want to create a blog website

    let me know your thoughts

  • webatonic1
    • Site Builder, Child of Zeus

    @Ignacio is it possible to have a User registration form for each individual template?

    That way people preview the template first and if they like it they choose it and fill out the form to create it. Similar to what SquareSpace.com has in their signup process.

  • webatonic1
    • Site Builder, Child of Zeus

    @Ignacio sorry for bombarding this thread but i got a reply with the new filter from Gravity forms support, file version 1.8.7 is attached below

    -----------------------------------------------------
    Hi Yevgeny,

    I've added a new hook per your request.

    add_filter( 'gform_user_registration_new_site_meta', 'add_blog_template', 10, 6 );
    function add_blog_template( $site_meta, $form, $entry, $feed, $user_id, $is_update_feed ) {

    $signup_meta['blog_template'] = 1;
    return $signup_meta;
    }

    This should do the trick. :slight_smile:

    Best,
    ------------------------------------------------------

    https://www.dropbox.com/s/6i00we1mpimh33b/gravityformsuserregistration_1.8.7.zip
    @Ignacio

  • Tyler Postle
    • CGO

    @Ignacio is it possible to have a User registration form for each individual template?

    That way people preview the template first and if they like it they choose it and fill out the form to create it. Similar to what SquareSpace.com has in their signup process.

    ^ This would be a really cool feature! +1

    @Ignacio sorry for bombarding this thread but i got a reply with the new filter from Gravity forms support, file version 1.8.7 is attached below

    Super fast turn around by the Gravity Forms team! Awesome :smiley:

  • webatonic1
    • Site Builder, Child of Zeus

    it could work something as follows....

    1) each gravity form can be paired with a template, so you would have to create a new form for each template. (at-least have the option to do that, in order to replicate what squarespace.com has)

    2) Use the Incoming Field Data
    Check this option to enable data to be passed to the form and pre-populate this field dynamically. Data can be passed via Query Strings, Shortcode and/or Hooks (not sure about this one)

    3) or both... :0

  • Ignacio
    • HummingBird

    Hi there and sorry for the late here.

    @webatonic1: I'll take note of your suggestiops but I don't know if attach a Gravity Form to a template would be viable, I'd like to take a look at that so I'll add this thread as a possible new feature.

    About your front'-end issue. I don't know what's happening, it's working great for me, have you followed all my steps? You also need to set a page for the form: Go to Forms>Settings>User registration and select a page there.

    ANyway, I attached here the latest version of New Blog Templates (still not released). Just overwrite yours and try again.

    Regards.
    Ignacio.

  • webatonic1
    • Site Builder, Child of Zeus

    Hi @Ignacio,

    It was actually working but it was attached to the first GF form from the 3 different ones I created. I had 3 forms total and created a user registration for the the 3rd form. For some reason the blog templates were showing up under the 1st form, and the form attached was the 3rd.

    Possible Feature: perhaps integrating NBT into the GF radio buttons can work.

  • Ignacio
    • HummingBird

    Hi @webatonic1.

    I'm not completely sure if that's even possible so I'll add this thread to the features list and test it a little but it seems out of the box for the plugin. For most users, one form should be more than enough. If I find an easy solution I'll tell you more or less how to do it.

    Regards.
    Ignacio.

    • webatonic1
      • Site Builder, Child of Zeus

      @Ignacio, I have been looking for a way to assign a single template to a Gravity Form, but have run into a wall.

      I have gone through some files of Gravity User Registration and New Blog Template files already and found that it is not possible because Gravity Forms plugin overrides all the metadata that New Blog Templates pass to WordPress.

      Is there a way I can go around this? what do I need to do?

      appreciate your advise here

  • Saurabh
    • New Recruit

    Hi @webatonic1,

    Hope you are well today.

    Assigning just one template, each to each of the three forms, is going to be a bit complicated. I'm looking into this and will get back to you, as soon as I am able to explore all the possibilities, here.

    Thank you for your patience.

    Best

    Saurabh

  • webatonic1
    • Site Builder, Child of Zeus

    @Saurabh Shukla,

    I contacted Gravity Forms support with the same question, and they said the following...

    "I'm not sure I understand the issue. With the new gform_user_registration_new_site_meta hook, you have access to alter the site's meta completely before it is created. What limitation are you running into?"

    so it is possible?

  • Ignacio
    • HummingBird

    Hi @webatonic1.

    It seems that I was a little blind :slight_smile:. GF code is a little confusing, it signup a blog in two different places of the code but I'm not sure why.

    Anyway, attached to this post you'll find another version of New Blog Templates with the additional filter. It worked for me. Remember to mark options "Create a new site" and "Display New Blog Templates Selector" in Forms>User Registration.

    Let me know how it goes :slight_smile:

    Regards.
    Ignacio.

  • webatonic1
    • Site Builder, Child of Zeus

    @Ignacio, I have installed the version you attached but I still can not see a way to select a specific Blog Template inside the GF user registration form settings page, it still looks exactly the same with just one option to "Display the Template Selector".

    Are you able to see something i'm not?

  • Ignacio
    • HummingBird

    Hi @webatonic1.

    New Blog Templates is not going to include a template ID option by default however I realized that is not such a big deal so I coded a little plugin that will make it work.

    Just unzip and upload the attached file to your wp-content/mu-plugins folder. This new plugin will override some of the integration between New Blog Templates and GF. You'll see now a new field that allows you to select a template for the form.

    Let me know if that was your idea :slight_smile:

    Regards.
    Ignacio.

    • Joe
      • General Design Monkey

      Hey guys - sorry so to resurrect this one, but I'm looking to get this working on my multisite. I've downloaded the plugin file you mention in this post (well the most recent one) and added to my muplugins directory. Doesn't seem to add anything to the forms backend though - I still just get 'display templates selector" . Should this still work with latest versions?

  • webatonic1
    • Site Builder, Child of Zeus

    @Ignacio, I installed the nbt-hook.php and finally see the field inside, this is exactly what I was looking for, unfortunately when I tested it out by assigning a specific template and creating a new test site the "default blog template" was used instead, I proceeded to remove the "default template" and test without any template being "default", but on this test the test site created was just blank.

    What should I do?

  • webatonic1
    • Site Builder, Child of Zeus

    @Ignacio, its not the settings I double checked, its that the feature only works with the FIRST gravity form you create, when you create a second it doesn't work.

    I tried it with the Gravity Form (ID1) and it worked like you said, but when i create a second, third, fourth Gravity Form it doesn't work.

  • Ignacio
    • HummingBird

    Hi again.

    It seems that I was using a function that was not appropiate to get the template value so I fixed that but GF works in a weird way and I realized that you cannot use two different User Registration feeds for the same form. So, you need to create one form + one User Registration feed for every template. I know is annoying but I believe that is the only way to make it work.

    You should also uncheck the "Custom Registration Page" option in Forms>Settings>User Registration as you should create (yes, again) a different page for every template too or at least I couldn't make it work with two different forms in the same page. I have to say that GF is a big plugin so maybe there's another way but I couldn't find it.

    That said, here's the new nbt-hooks.php file :slight_smile:.

    Let me know how is working now. Let me know also how do you set up your forms/feeds, please.

    Just another note. If you want to know which is the template attached to a form from the frontend, inside nbt-hooks.php, line 63, change type="hidden" for type="text". If a text field appears next to the submit button in the form with a number, that means that the template will work. That number is the template ID. That could help you to know if the plugin is working or not instead of create tests sites over and over.

    Regards.
    Ignacio.

  • Arom77
    • Froggy

    I've just seen this:

    Version: 2.6.8
    Release Date: 2014-06-25 Downloads: 38 Compatible With: Multisite 3.9.1BuddyPress 2.0.1
    Changelog:

    - Added Gravity Forms Integration

    OMG. Can't believe that.
    Could you tell us more about this?

    Thanks a lot!

    PS : Maybe I should have opened a new topic?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.