Using Gravity Forms ‘gform_require_login’ PHP action

The gform_require_login filter in Gravity Forms can be used to override the form’s requireLogin property, which determines whether the user needs to be logged in to view and use the form.

Usage

A generic example of using the filter for all forms:

add_filter('gform_require_login', 'your_function_name', 10, 2);

To limit the scope of your function to a specific form, append the form ID to the end of the hook name (format: gform_require_login_FORMID):

add_filter('gform_require_login_6', 'your_function_name', 10, 2);

Parameters

  • $require_login (boolean): Indicates if the user must be logged in to view and use the form. Default is false. Will be true if the “Require user to be logged in” setting is enabled.
  • $form (Form Object): The form currently being viewed or processed.

More information

See Gravity Forms Docs: gform_require_login

This filter was added in Gravity Forms v2.4. It was moved to GFCommon::form_requires_login() in version 2.6.8.1.

This filter is located in GFCommon::form_requires_login() in common.php.

Examples

Enable for ALL forms

This example requires users to be logged in to view and use all forms:

add_filter('gform_require_login', '__return_true');

Disable for ALL forms

This example allows logged-out users to view and use all forms:

add_filter('gform_require_login', '__return_false');

Perform custom check during multi-file upload

This example performs custom checks during multi-file upload:

add_filter('gform_require_login', function($require_login, $form) {
    if (!class_exists('GFAsyncUpload')) {
        return $require_login;
    }

    // Perform custom checks here.
    // Return false to prevent GFAsyncUpload validating that the user is logged in.

    return $require_login;
}, 10, 2);