Web development and useful information

person encoding in laptop

Allow Create and Update feeds with the Gravity Forms User Registration Add-On plugin

The Gravity Forms User Registration Add-On plugin allows you to Create (or Update) a WordPress user and their meta fields from a Gravity Form’s fields. It’s a great plugin.

By default, it only allows one feed type per form: a Create OR an Update feed.

I build a lot of Membership Application forms with Gravity Forms. I used to build two forms per User Registration feed: one for logged-out users and another for logged-in users. It was annoying for me and our clients to maintain two forms.

I spent some time seeing if I could use both a Create and Update feed on one form, triggering one or the other feed based on a user’s log-in state.
I found a way to do it. I’m sharing the code in case it’s useful to anyone.

To use this code, copy the class into a plugin (or your theme). Then call gravity_forms_user_registration::init() from an action such as ‘plugins_loaded’.

Previous

Beginner’s guide to record collecting

Next

WordPress Bookmarklets

10 Comments

  1. AJ

    Hi, thanks for sharing this. However I cannot get it to work… Please help.

    I have included a file named ‘gravity-forms-user-registration.php’ which contains your code, and have called it inside a hook using the example you gave:
    add_action( ‘plugins_loaded’, array( ‘gravity_forms_user_registration’, ‘init’ ) );

    The issue I’m having is on the backend of Gravity Forms, when I Edit my Form Settings and go to User Registration, where I can create a new Feed… the option to add a new Update Feed is disabled when I already have a Create Feed.

    How do I get around this? I tried simply removing the disabled=1 from the front-end HTML using Inspect Element, and that got me one step further, but I was thrown an error when I tried to Save.

    Thanks,
    AJ

    • AJ

      Hi, ignore the previous comment – I was missing a line from my functions file…

      Previously I had in functions.php:
      include ‘gravity-forms-user-registration.php’;
      add_action( ‘plugins_loaded’, array( ‘gravity_forms_user_registration’, ‘init’ ) );

      Now I have:
      include ‘gravity-forms-user-registration.php’;
      add_action( ‘plugins_loaded’, array( ‘gravity_forms_user_registration’, ‘init’ ) );
      gravity_forms_user_registration::init();

      So it seems I was just missing: gravity_forms_user_registration::init();

      However I have a new problem now…
      Now that I have successfully created an ‘Update’ Feed alongside my ‘Create’ Feed for the same form, when I test the form using a logged-in user, although the form submits and appears to work (and it even creates the Tx and Sub in Stripe) it does not however create a Tx or Sub within MemberPress.
      The result is that a subscription exists in Stripe but MemberPress does not register it.
      Any ideas what could be wrong?

      I have tested my setup using a separate form, which only has an Update Feed, not both… and this works fine. So I know that the rest of my setup is all functioning correctly it just appears not to work when the form has both an Update Feed together with a Create Feed.

  2. Alice

    Thank you SO much for sharing this. It’s exactly what I’ve been looking for and it did the job perfectly. Thank you!

  3. Hi OP,

    Great post.

    The Gravity Forms User Registration add-on does not inherently provide the functionality to log in a user during the submission of a form that is connected to an “Update User” feed. The add-on expects the user to be already logged in when filling out an “Update User” feed form.

    Do you have a workaround to get the “Update User” Feed to log a user in and save the response?

    • Hi Nish,

      I don’t think I understand your use case, sorry.

      Do you have a workaround to get the “Update User” Feed to log a user in and save the response?

      The Update User feed is only triggered if the user is logged in already.

      For logging in newly created users I use this Gravity Perk plugin: https://gravitywiz.com/documentation/gravity-forms-auto-login

      My Create feed handles:
      1. Creating a new WordPress user with fields submitted in the form.
      2. Auto Login then logs the user in automatically, once created.

      My Update feed handles
      1. WordPress user is already logged in.
      2. Updating the WordPress user’s details with fields submitted in the form.

      In my case I then only need one form with both a Create and Update feed, and this other auto login plugin.

      What do you need to do?

  4. This looks great.

    So, can I use the snippet as provided in a plugin like Code Snippets without any additional info versus using pasting into functions.php?

    • Hi Scot,

      I’ve not used Code Snippets, but pasting this code there should work fine.

      To use this code with Code Snippets, you would paste the class into code snippets (just line 3 – 141 above, leaving out the opening PHP tag).

      Then directly below the pasted code use this action to call the class init method:
      add_action( ‘plugins_loaded’, array( ‘gravity_forms_user_registration’, ‘init’ ) );

  5. Hi Nathan,

    This code has allowed us to setup a create and update feed, we have verified that create is working however on update we get the following error from ‘User Registration Add-On’ debug log.

    2024-05-28 11:18:26.966670 – DEBUG –> GFFeedAddOn::maybe_process_feed(): Feed processing is delayed, not processing feed for entry #68 for gravityformsuserregistration

    Any ideas ?

    • Hi Josh,

      There was a change a while ago where feeds were made asynchronous.
      I remember when that happened as we needed to change our user registration feed back to being synchronous again.

      You may be able to use this filter to stop user registration feeds from being asynchronous. Hopefully this solves the problem.

      /**
      * gravityformsuserregistration can create two feeds: create and update.
      * Create is async disabled.
      * Update is async enabled.
      * We want Update feeds to be async disabled also.
      *
      * @param bool $is_async_feed_enabled
      * @param array $feed
      * @param array $entry
      * @param array $form
      *
      * @return boolean
      */
      function gravity_forms_disable_async_processing_for_user_registration_feeds( bool $is_async_feed_enabled, $feed, $entry, $form ) {
      if ( ! empty( $feed[‘addon_slug’] ) && ‘gravityformsuserregistration’ === $feed[‘addon_slug’] ) {
      return false;
      }

      return $is_async_feed_enabled;
      }
      add_filter( ‘gform_is_feed_asynchronous’, ‘gravity_forms_disable_async_processing_for_user_registration_feeds’, 10, 4 );

      Please leave a comment if this solves it. I’ll update this blog post and add this filter as a requirement to get both create and update feeds working.

  6. Josh

    Hi Nathan,

    I’ve tested this below the following code in my functions.php however it didn’t work

    include ‘gravity-forms-user-registration.php’;
    add_action( ‘plugins_loaded’, array( ‘gravity_forms_user_registration’, ‘init’ ) );
    gravity_forms_user_registration::init();

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Powered by WordPress & Theme by Anders Norén