gform_require_login

Description

The gform_require_login filter can be used to override the form requireLogin property; does the user need to be logged in to view and use the form?

Usage

The filter which runs for all forms would be used like so:

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 vewied or processed.

Examples

Enable for ALL forms

This example shows how you can require users to be logged in to view and use all forms.

add_filter( 'gform_require_login', '__return_true' );

Disable for ALL forms

This example shows how you can enable logged out users to view and use all forms.

add_filter( 'gform_require_login', '__return_false' );

Perform custom check 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 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

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

Source Code

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