gform_user_registration_config_validation

gform_user_registration_config_validation

DescriptionUsageParametersExamplesSource Code

Removed: This filter was removed in version 3.0. New feed settings defined using gform_userregistration_feed_settings_fields can be validated by defining the validation_callback property for the field.

Description
Used to validate custom settings/meta specified using the gform_user_registration_add_option_section or gform_user_registration_add_option_group action hooks.
Usage
add_filter( 'gform_user_registration_config_validation', 'your_function_name', 2 );

Parameters

$is_validation_error array
Boolean value indicating whether there was a validation error with the User Registration configuration.

$config array
The User Registration configuration array.

Examples
This example is a bit of modified code from the User Registration source code that demonstrates how to validate the custom option fields added using the gform_user_registration_add_option_section hook to support the MultiSite options.
add_filter( 'gform_user_registration_config_validation', 'validate_multisite_config' );
public static function validate_multisite_config( $is_validation_error ) {

$multisite_options = $config['meta']['multisite_options'];

if(empty($multisite_options['create_site']))
return $is_validation_error;

if(empty($multisite_options['site_address']) || empty($multisite_options['site_title']))
return true;

return $is_validation_error;
}

Source Code
This action hook is located in userregistration.php.

gform_user_registration_check_email_pre_signup_activation

gform_user_registration_check_email_pre_signup_activation

DescriptionUsageParametersPlacementSinceSource Code

Description
This filter can be used to disable the check for an email already being used by a registered user allowing the use of custom code or third-party plugins to bypass this WordPress core limitation in the registration process.
Usage
add_filter( 'gform_user_registration_check_email_pre_signup_activation', '__return_false' );

If you plan to use this filter to allow users to use already registered emails for new registrations, you need to use also the gform_user_registration_validation filter.

Parameters

$check_email bool
True or false.

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms User Registration Add-On 2.4.2.
Source Code
$check_email = apply_filters( 'gform_user_registration_check_email_pre_signup_activation', true );

This filter is located in GFUserSignups::activate_signup() in signups.php.

gform_user_registration_add_option_section

gform_user_registration_add_option_section

DescriptionUsageParametersExamplesSource Code

Removed: This hook was removed in version 3.0 and replaced by gform_userregistration_feed_settings_fields.

Description
Used to add a custom option section to the User Registration Feed (similar to how BuddyPress and MultiSite are integrated with the User Registration add-on).
Usage
Applies to all forms.
add_action( 'gform_user_registration_add_option_section', 'your_function_name', 10, 3 );

Parameters

$config array
The User Registration configuration array.

$form Form Object
The Form Object for which the current user registration feed is for.

$is_validation_error boolean
Boolean value indicating whether there was a validation error with the User Registration configuration.

Examples
This example is a bit of modified code from the User Registration source code that demonstrates how the Multi-Site section was added to the feed page.
add_action( 'gform_user_registration_add_option_section', 'add_multisite_section', 10, 3 );
function add_multisite_section( $config, $form, $is_validation_error ) {

get_current_site();

$form_fields = self::get_form_fields($form);
$multisite_options = $config['meta']['multisite_options'];
$parent_blog = get_dashboard_blog();
$current_blog = $GLOBALS['blog_id'];

if($parent_blog->blog_id != $current_blog)
return;

?>

Multisite Options


onclick="if(this.checked){jQuery('#multisite_option_items').fadeIn('fast');} else{jQuery('#multisite_option_items').fadeOut('fast');}" />





gform_user_registration_add_option_group

gform_user_registration_add_option_group

DescriptionUsageParametersExamplesSource Code

Removed: This hook was removed in version 3.0 and replaced by gform_userregistration_feed_settings_fields.

Description
Used to add a group of options to the 「Additional Options」 section of the User Registration Feed. Useful when you want to add one or two options without requiring a whole section.
Usage
Applies to all forms.
add_action( 'gform_user_registration_add_option_group', 'your_function_name', 10, 3 );

Parameters

$config array
The User Registration configuration array.

$form Form Object
The Form Object for which the current user registration feed is for.

$is_validation_error boolean
Boolean value indicating whether there was a validation error with the User Registration configuration.

Examples
This example shows how to add the 「Send User Email」 option (available by default in the User Registration) using the gform_user_registration_add_option_group as if this option was no already available.
add_action( 'gform_user_registration_add_option_group', 'add_custom_group', 10, 3 );
function add_multisite_section( $config, $form, $is_validation_error ) {
?>


/>

gform_user_registered

gform_user_registered

DescriptionUsageParametersExamplesUpdate user metaSet user roleTrigger Mailchimp feedUpdate entry created_by propertyAdd additional user rolePlacementSource Code

Description
This action is used to trigger an event once a user has been registered through the User Registration Add-on.
Usage
Applies to all forms
add_action( 'gform_user_registered', 'your_function_name', 10, 4 );

Parameters

$user_id integer
The ID of the registered user.

$feed Feed Object
The Feed which is currently being processed.

$entry Entry Object
The entry object from which the user was registration.

$user_pass string
The password associated with the user; either submitted by the user or sent via email from WordPress.

Examples
Update user meta
Here is an example from the User Registration source code where BuddyPress profile data is added for the user using the gform_user_registered hook.
add_action( 'gform_user_registered', 'add_custom_user_meta', 10, 4 );
function add_custom_user_meta( $user_id, $feed, $entry, $user_pass ) {
update_user_meta( $user_id, 'user_confirmation_number', rgar( $entry, '1' ) );
}

Set user role
The following example shows how you can set the user role based on the value of a field.
add_action( 'gform_user_registered', 'set_user_role', 10, 3 );
function set_user_role( $user_id, $feed, $entry ) {
// get role from field 5 of the entry.
$selected_role = rgar( $entry, '5' );
$user = new WP_User( $user_id );
$user->set_role( $selected_role );
}

Trigger Mailchimp feed
This example shows how you can trigger the processing of Mailchimp feeds for this entry.
add_action( 'gform_user_registered', 'send_to_mailchimp', 10, 3 );
function send_to_mailchimp( $user_id, $feed, $entry ) {
if ( function_exists( 'gf_mailchimp' ) ) {
$form = GFAPI::get_form( $entry['form_id'] );
gf_mailchimp()->maybe_process_feed( $entry, $form );
}
}

Update entry created_by property
This example shows how you can update the entry created_by property with the ID of the new user.
add_action( 'gform_user_registered', 'sh_gform_user_registered', 10, 3 );
function sh_gform_user_registered( $user_id, $config, $entry ) {
GFAPI::update_entry_property( $entry['id'], 'created_by', $user_id );
}

Add additional user role
This example shows how you can add an additional user role based on the value of a field.
add_action( 'gform_user_registered', 'add_user_role', 10, 3 );
function add_user_role( $user_id, $feed, $entry ) {
// get role from field 5 of the entry.
$selected_role = rgar( $entry, '5' );
$user = new WP_User( $user_id );
$user->add_role( $selected_role );
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
do_action( 'gform_user_registered', $user_id, $feed, $entry, $user_data['password'] );

This filter is located in GF_User_Registration::create_user() in class-gf-user-registration.php.

gform_use_post_value_for_conditional_logic_save_entry

gform_use_post_value_for_conditional_logic_save_entry

DescriptionUsageParametersExamples

Description
The 「gform_use_post_value_for_conditional_logic_save_entry」 filter in Gravity Forms specifies whether to fetch values from the $_POST when evaluating a field』s conditional logic. Defaults to true for new entries and false for existing entries.
Usage
The following would apply to all forms.
add_filter( 'gform_use_post_value_for_conditional_logic_save_entry', 'your_function_name', 10, 3 );

To limit the scope of your function to a specific form, append the form ID to the end of the hook name.
Format: gform_use_post_value_for_conditional_logic_save_entry_FORMID
add_filter( 'gform_use_post_value_for_conditional_logic_save_entry_6', 'your_function_name', 10, 3 );

Parameters

$read_value_from_post array
Should the value be fetched from the $_POST?

$form Form Object
The current form object.

$entry Entry Object
The current entry object.

Examples
Enable fetching from post by default:
add_filter( 'gform_use_post_value_for_conditional_logic_save_entry', '__return_true' );

gform_use_mcrypt

gform_use_mcrypt

Description

Description
The 「gform_use_mcrypt」 filter in Gravity Forms indicates whether the function 「mcrypt_encrypt」 should be used for encryption. This filter was called in Gravity Forms』 encrypt/decrypt functions in the GFCommon class. These functions have been deprecated as of Gravity Forms version 2.3, meaning the filter will no longer be used for encryption.
The new functions used for encryption are 「openssl_encrypt」 and 「openssl_decrypt」 which do NOT use mcrypt.

gform_us_states

gform_us_states

DescriptionUsageParametersExamples1. Use State Code2. Remove States3. Add Outlying Territories to US State ListPlacementSource Code

Description

This filter can be used to modify the choices listed in the US states drop down.

Usage

add_filter( 'gform_us_states', 'your_function_name' );

Parameters

$states array
The array to be filtered. It contains the list of states in a standard array (see sample below).
array( 'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', ... );

Examples

1. Use State Code

This example demonstrates how to use the two letter state code as the choice value.

add_filter( 'gform_us_states', 'us_states' );
function us_states( $states ) {
$new_states = array();
foreach ( $states as $state ) {
$new_states[ GF_Fields::get( 'address' )->get_us_state_code( $state ) ] = $state;
}

return $new_states;
}

2. Remove States

add_filter( 'gform_us_states', 'filter_us_states' );
function filter_us_states( $states ) {
$omit_states = array(
'Alaska',
'Hawaii'
);

foreach ( $states as $key => $state ) {
if ( in_array( $state, $omit_states ) ) {
unset( $states[ $key ] );
}
}

return $states;
}

3. Add Outlying Territories to US State List

add_filter( 'gform_us_states', 'us_states' );
function us_states( $states ) {

$territories = array(
2 =>'American Samoa',
12=>'Guam',
37 =>'Northern Mariana Islands',
42 =>'Puerto Rico',
48 =>'United States Minor Outlying Islands',
49 =>'U.S. Virgin Islands'
);

foreach ( $territories as $key => $t ) {
array_splice( $states, $key, 0, $t );
}
return $states;
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GF_Field_Address::get_us_states() in includes/fields/class-gf-field-address.php.

gform_upload_root_htaccess_rules

gform_upload_root_htaccess_rules

DescriptionUsageParametersExamplesPrevent Gravity Forms from adding default rules to the fileAdd new new rules to the .htaccess filesPlacementSource Code

Description
A filter to allow to turn off or modify rules being added to the .htaccess file created for the base upload path.
Please consult your system administrator before using this filter.
Usage
The following would apply to all forms.
1add_filter('gform_upload_root_htaccess_rules', 'my_filter_function');

Parameters

$rules Mixed
The Rules of what to parse or not to parse

Examples
Prevent Gravity Forms from adding default rules to the file
This will only stop Gravity Forms from adding the default rules to the .htaccess file created, after the removal of the existing .htaccess file done daily by the cron task gravityforms_cron
1add_filter( 'gform_upload_root_htaccess_rules', '__return_false' );
Add new new rules to the .htaccess files
The example below would allow you to add new lines to the .htaccess being regenerated by cron task.
123456add_filter( 'gform_upload_root_htaccess_rules', function( $rules ) {    $rules[] = 'a new line in the file';    $rules[] = 'another new line';    GFCommon::log_debug( __METHOD__ . '(): .htaccess rules => ' . print_r( $rules, true ) );    return $rules;} );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in common.php

gform_upload_path

gform_upload_path

DescriptionUsageParametersExamples1. Log the current path2. Change the path and urlPlacementSource Code

Description

This filter is executed before uploading a file (by the File Upload or Post Image fields). It can be used to change the location where uploaded files are stored.

Usage

The following would apply to all forms.

1add_filter( 'gform_upload_path', '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_upload_path_FORMID)

1add_filter( 'gform_upload_path_5', 'your_function_name', 10, 2 );

Parameters

$path_info array
The upload path to be filtered. It is an associative array with two keys which must be specified.

$path_info[『path』] string
Full physical path to upload folder.

$path_info[『url』] string
Full URL to upload folder.

$form_id integer
The ID of the form currently being processed.

Examples

1. Log the current path

You can use this example when logging is enabled to find out what the current path is before using the next example to change the path.

12345add_filter( 'gform_upload_path', function ( $path_info, $form_id ) {    GFCommon::log_debug( "log_upload_path(): path_info for form #{$form_id} => " . print_r( $path_info, true ) );     return $path_info;}, 1, 2 );

2. Change the path and url

This example changes the upload path and url for the File Upload field. Note: The default secure 「gf-download」 links will work only with the default upload path, therefore if you use this filter you can』t use the 「gf-download」 links.

123456add_filter( 'gform_upload_path', 'change_upload_path', 10, 2 );function change_upload_path( $path_info, $form_id ) {   $path_info['path'] = '/home/public_html/yourdomainfolder/new/path/';   $path_info['url'] = 'http://yourdomainhere.com/new/path/';   return $path_info;}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GFFormsModel::get_file_upload_path() in forms_model.php.