Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    • Documentation
    • Support
    • Account

Skip User Registration For Logged In Users

Last updated February 20, 2020 | Written by David Smith 47 Comments

  • February 20, 2020: Fixed issues caused by failure to return $form object.

  • November 16th, 2015: Update to work with GFUR v3.0.beta1+. Props to GF team member Richard Vav.

If you’re using the Gravity Forms User Registration Add-on, this snippet will allow you to skip registration for users who are logged in when they submit the form.

Download Code
<?php
/**
* Skip Registration for Logged In Users
* http://gravitywiz.com/2012/04/24/skip-user-registration-for-logged-in-users/
* Works for GF User Registration 3.0 and greater.
*/
add_filter( 'gform_is_delayed_pre_process_feed', 'maybe_delay_feeds', 10, 4 );
function maybe_delay_feeds( $is_delayed, $form, $entry, $slug ) {
if ( is_user_logged_in() && $slug == 'gravityformsuserregistration' ) {
return gf_user_registration()->has_feed_type( 'create', $form );
}
return $is_delayed;
}
add_action( 'gform_pre_process', 'maybe_skip_validation' );
function maybe_skip_validation( $form ) {
if ( is_user_logged_in() && function_exists( 'gf_user_registration' ) && gf_user_registration()->has_feed_type( 'create', $form ) ) {
remove_filter( 'gform_validation', array( gf_user_registration(), 'validate' ) );
}
return $form;
}
view raw gw-gravity-forms-skip-registration-for-logged-in-users.php hosted with ❤ by GitHub
This snippet has been updated to work with the very latest version of the Gravity Forms User Registration plugin (3.0.beta1+). If you’re not ready to upgrade, or need to accomplish this functionality on an earlier version, use this snippet instead.

This snippet was written to assist a fellow who had configured a form that allowed users to optionally register an account on the site. This much is handled out of the box by the GF User Registration Add-on.

The issue arose when users, who opted to create an account on their initial submission, neglected to click the checkbox which opted them out of creating an account on their subsequent submissions. This resulted in a validation error; the submitted email was already registered to a user on the site!

Of course it was! It is the very email the user previously created an account with. The solution? If the user is logged in skip the registration completely. Be sure to display a message somewhere on your form instructing users to login if they already have an account.

Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 32+ essential add-ons for Gravity Forms with support you can count on.

  • View All Perks
  • Buy Gravity Perks

Filed Under: Snippets

Comments

  1. stephane samandoulougou says

    March 29, 2020 at 3:19 pm

    hello how can use code? can i add the code in functions.php?

    Reply
    • Ryan Donovan says

      March 29, 2020 at 7:57 pm

      Hello Stephane, That is correct. You will be inserting this into your themes functions.php file. For more troubleshooting help, check out our help article here. 😀

    • stephane samandoulougou says

      March 30, 2020 at 3:02 pm

      Thank you for your answer. At the very beginning I copied the code into my funtions.php file but nothing happens in my site.

      I installed gravity forms, the gravity useregistration and paypal payment module. Should i installed gravitywiz?

    • Ryan Donovan says

      March 30, 2020 at 4:45 pm

      Hey Stephane, What version of User Registration are you using? Please note: This snippet has been updated to work with the very latest version of the Gravity Forms User Registration plugin (3.0.beta1+). If you’re not ready to upgrade or need to accomplish this functionality on an earlier version, use this snippet instead. You should be fine with your setup plus this snippet. If you’re a Gravity Perks customer, we’ll be happy to provide support via the support form.😁

  2. Matt Kiba says

    November 19, 2018 at 8:18 pm

    Code is corrupt. Submit button disappears for multi-page forms

    Reply
    • Matt Kiba says

      November 19, 2018 at 8:22 pm

      Never mind, this turned out to be theme specific

  3. Fabienne Wintle says

    July 26, 2018 at 8:28 pm

    Hi, is there a way to actually display the form to non logged in users if user registration (update user) is turned on? I have a form that I would like both logged in and logged out users to use, and user registration is enabled with conditional logic to only apply to users that are logged in. However, even with this logic being applied the form does not display if users are logged out. Which doesn’t make sense.

    So I found your gist which does the opposite of what I need and was wondering if you had something to achieve my objective?

    Reply
    • David Smith says

      July 29, 2018 at 7:05 pm

      Hi Fabienne, hm, I’m not sure I followed. Could you explain your end goal?

    • Ibraheem says

      June 26, 2019 at 8:05 am

      Hi David, I’m having this issue also, so I’d be grateful if you have a solution. When selecting ‘Update User’ for the form action, the form then seems to be locked for users who are not logged in. The use case is for ensuring that logged in users don’t have to fill out information they’ve already entered in the past, but still allow guest users to submit as well (without creating a new user of course). Do you know of a solution to this?

  4. Jeffrey says

    June 20, 2018 at 3:00 am

    I added the code to my functions.php , but now when I fill in my form the confirmation email from the form does not arrive to my email…

    Reply
    • David Smith says

      June 20, 2018 at 7:54 am

      Hi Jeffrey, this doesn’t interact with the confirmation functionality so it is unlikely that this snippet is interfering with any core Gravity Forms functionality. If you’re a Gravity Perks customer, we’ll be happy to provide support via the support form.

  5. Seb says

    June 25, 2017 at 7:55 am

    Is it possible to customize this code? I would like to do following:

    If Email Address exists skip registration and update data for non-logged-in-users

    Thx

    Reply
    • David Smith says

      June 25, 2017 at 8:35 am

      Hi Seb, I have a resource for updating by email on “Update” feeds but not on “Create” feeds: https://gist.github.com/spivurno/3bb450d5469df7b10f6d273a6cd24272

    • Seb says

      June 25, 2017 at 8:56 am

      Hi David, thx.

      I`ve just tested it. But it only says if user is not logged in: Email alreads exists.

    • David Smith says

      June 25, 2017 at 3:11 pm

      Yeah, I realized after posting that there is some other code required to get this to work. Try adding this snippet as well.

      https://gist.github.com/spivurno/c7ec7c871760e8e0ea5ed914d9fbfaf5

    • Tim French says

      August 14, 2017 at 8:58 am

      Hi David, just wondering if you where considering a version for create feeds?

      the problem is causing me a few headaches at the mo…..

      Tim

    • David Smith says

      August 14, 2017 at 11:15 am

      Hi Tim, I don’t have any definite plans but if you’d like to commission the functionality, I’d be happy to discuss: david at graitywiz dot com

  6. Kev Xaveus says

    April 22, 2017 at 9:08 am

    noob question: where does the snippet need to be pasted? Does it go in the theme’s functions.php or the WP-includes functions.php?

    Does it go at the top or end of the PHP file and does it go within the main <PHP? content or does it keep its own PHP bracket?

    Could you post a screenshot of it pasted as it should be please?

    Reply
    • David Smith says

      April 22, 2017 at 9:35 am

      This will help: https://gravitywiz.com/documentation/snippet-troubleshooting/

  7. wahab says

    July 22, 2016 at 8:14 am

    hi david, can you please advise how to make this code works when user is NOT logged-in?

    Reply
  8. Marshall says

    July 9, 2016 at 7:49 am

    Hi

    This not working for me. Still getting email address already registered.

    Reply
    • David Smith says

      July 14, 2016 at 7:51 pm

      Are you using the latest version of the snippet above? Is the user actually logged in?

    • Marshall says

      July 14, 2016 at 7:58 pm

      yes…the above code.

      yes…admin logged in..

      I wanted the field to show when user role is administrator.

      Can you give me example on how I can do this?

    • David Smith says

      July 14, 2016 at 8:10 pm

      Hi Marshall, I just confirmed that this snippet is working for me. Based on your last comment, I think you might be wanting to hide a field based on the user role. You can do this by populating the user role into a field on the form and then basing the conditional logic on the value of that field. This will help:

      https://gravitywiz.com/dynamically-populating-user-role/

  9. Tuhin Bhuiyan says

    June 10, 2016 at 12:54 pm

    Is this snippet still working?. for version RC1 beta3.

    For me, it is still showing the user field and asking for validation.

    Reply
    • David Smith says

      June 30, 2016 at 10:03 am

      Hi Tuhin, yes, this is working on our end with the latest versions of Gravity Forms and GF User Registration.

  10. Russell Weller says

    December 17, 2015 at 5:31 pm

    Hi. I am trying to modify your snippet to skip registering the user if a user already exists. Having some problems though. Wondered if you might be able to help …

    Here’s what I’ve got so far, but the registration goes through even though the value of Form ID 1, Field ID 11 matches an existing user, which then throws an error on the front-end since the username already exists.

    [code removed]

    Reply
    • Russell Weller says

      December 17, 2015 at 5:32 pm

      I posted on Pastie.org.

    • Russell Weller says

      December 17, 2015 at 5:33 pm

      http://pastie.org/10638856

    • David Smith says

      December 18, 2015 at 7:46 am

      Hi Russell, I can’t confirm that this works but it might get you a little closer. The basic idea is that you can just check the $_POST for the submitted username rather than setting up another filter level via the get “gform_get_input_value” filter.

      http://pastie.org/private/h8rd3bjcm92a4ym8raq#9,18

    • Russell Weller says

      December 18, 2015 at 1:10 pm

      Thanks David! I’m still doing some testing, but that code seems to have done the trick!

    • Russell Weller says

      March 28, 2016 at 12:18 pm

      Hi David! The pastie code you posted was working great, but seems to have broken on updating to GF 1.9.17.5 and User Registration 3.2.1. Any ideas?

    • Russell Weller says

      March 28, 2016 at 12:38 pm

      I can get it to work if I remove the “username_exists( rgpost( ‘input_17’ ) ) &&” from line 18. The ID of the input field I am checking is definitely 17, so not sure. That removes all validation on forms that Create a User though, not just the ones that have duplicate usernames.

    • David Smith says

      March 29, 2016 at 8:07 am

      Hey Russell, I took another look at the snippet and I can’t see any reason it shouldn’t work. You may need to hire a developer to assist with this one.

  11. Naser says

    October 7, 2015 at 6:01 pm

    Great Post!

    I have some other remaining problems with Gravity Form :

    1.) I would like to completely disappear User Registration form as an option to menu and the page for Login Users.

    2.) In an other form under Restrictions I have use “Require user to be logged in” but instead of “Require login message” I would like to make redirect user to login page.

    Do you have any idea, how to implement all the above?

    Thank You!

    Reply
    • David Smith says

      October 8, 2015 at 5:23 pm

      1 – Install the Members plugin and modify the user role for your users so that they do not have the “gravityforms_user_registration” capability. This will prevent users from seeing the User Registration menu item.

      2 – I would bind a function to the gform_pre_enqueue_scripts action. It passes the $form object as the first parameter. If the $form[‘requiresLogin’] option is set and the user is not logged in, you can use wp_redirect() to redirect to the URL of your choice.

  12. barbara schendel says

    March 26, 2015 at 12:31 pm

    This gets me close to what I need, thank you! One question — if it skips registration, will it still promote the person’s user role? My form charges money and promotes them to a different user role. Still need this if user is already logged in. (and I would like to not have to create two separate forms if possible since that just seems so inelegant!) Thanks!

    Reply
    • David Smith says

      March 26, 2015 at 10:52 pm

      Not quite. With this, either a user is created or nothing. It sounds like what you want is the Update User feed; however, the User Registration add-on won’t let you have a Create feed and an Update feed on the same form. In this case, you might consider using this snippet to promote the user if they’re logged in based on a field value:

      https://gist.github.com/spivurno/22d12bb094e0d939ec22

    • barbara schendel says

      March 27, 2015 at 11:01 am

      Awesome! Thank you!

  13. Rochel says

    August 11, 2014 at 1:32 pm

    I’m not sure if this solution would work for me and I’m hoping someone can help me tweak it or point me in the right direction. I have a gravity forms registration form for an annual event that is hooked up with paypal and charges a registration fee and creates a user account once the payment goes through.

    The problem is, that I have people returning to the event this year who need to pay a registration fee and need to update their info. through the registration form but their info is already associated with a wordpress user. I can’t disable the User Registration add-on because there are new people registering for the event using this same form and I need the form to go ahead and make them a user account. I’m also not sure I can create a separate form without confusing visitors and having them give up.

    Any ideas would be a big help.

    Thanks!

    Reply
    • David Smith says

      August 11, 2014 at 8:10 pm

      Hi Rochel,

      The easiest way to do this will simply be using two different forms. I don’t think users will be too confused by a quick message at the top of the form along the lines of “If you’re already a member, please renew here.” You could take it a step further and if they’re already logged in, just redirect them to the renewal form if they try to access the the registration form.

      The real benefit of using two separate forms is that you can use the User Registration add-on to handle updated the existing user on the renewal form to indicate that their account is good for another year. You could do this with a single form but it would be have to be custom coded.

  14. jochen says

    November 21, 2013 at 5:00 pm

    That’s cool, thanks for sharing!!!

    Is there a way to use the information if a user is logged in on other form conditionals???

    Thx

    Reply
    • David Smith says

      November 22, 2013 at 1:41 pm

      You can use the {user:meta_key} merge tag in any Default Value field and then apply conditional logic based on that populated field to handle other form conditions.

  15. mark says

    June 14, 2012 at 10:46 am

    Hi David,

     

    Can this be combined with an auto login function as http://www.gravityhelp.com/forums/topic/auto-login-after-successful-completion-of-form

    and

    http://www.gravityhelp.com/forums/topic/user-registration-login-redirect-to-private-page#post-31529

    so if the user is either not registered or not logged in they are given the same form and either registered and the form submitted or just submitted.

    Thanks

     

    Mark

    Reply
  16. Andy says

    May 29, 2012 at 8:01 pm

    This doesnt work. I pasted into functions.php and i still get email is already registered. pls help. thx

    Reply
    • David Smith says

      June 1, 2012 at 9:52 am

      Hi Andy, looks like I missed something pretty obvious. Overriding the validation! The snippet has been updated. Give it a shot. :)

Trackbacks

  1. gform_is_delayed_pre_process_feed – Gravity Forms Documentation says:
    October 4, 2017 at 3:11 pm

    […] This example prevents the User Registration ‘create’ feed running if the user is logged in. Read the full tutorial for details and the second part of the code snippet. […]

    Reply

Leave a Reply Cancel 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.

Categories

  • How To (64)
  • News (21)
  • Plugins (14)
  • Releases (7)
  • Resource (3)
  • Snippets (58)
  • Tutorials (57)
  • Updates (104)

Recent Posts

  • How to Send a Follow-Up and Pre-Fill Information
  • How to Update Posts with Gravity Forms
  • Gravity Wiz Weekly #104
  • The Complete Guide to Using Gravity Forms With Zapier
  • Gravity Wiz Weekly #103

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2021 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Gravity Perks
    ▼
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    ▼
    • Documentation
    • Support
    • Account