gform_address_zip

gform_address_zip

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed when creating the address zip field and can be used to modify the 「Zip」 label.
Usage
Applies to all forms
1add_filter( 'gform_address_zip', 'change_address_zip', 10, 2 );
Applies to a specific form. In this case, form Id 5
1add_filter( 'gform_address_zip_5', 'change_address_zip', 10, 2 );
Parameters

$label string
The label to be filtered.

$form_id integer
The current form』s id.

Examples
This example changes the default address zip label:
1234add_filter( 'gform_address_zip', 'change_address_zip', 10, 2 );function change_address_zip( $label, $form_id ) {    return "Address Zip";}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in js.php and GF_Field_Address::get_field_input() in includes/fields/class-gf-field-address.php.

gform_admin_error_messages

gform_admin_error_messages

DescriptionUsageParametersExamplesSource Code

Description
Modify error messages displayed by Gravity Forms in the WordPress admin.
Usage
1add_action( 'gform_admin_error_messages', 'my_custom_function' );
Parameters

$error_messages array
An array of error messages to be displayed below the title on Gravity Form pages.

Examples
This example demonstrates how we can remove an error message.
123456789101112131415add_action( 'gform_admin_error_messages', 'my_remove_error_message' );function my_remove_error_message( $errors ) {     // loop through our error messages    for ( $i = count( $errors ); $i > 0; $i-- ) {         // check if this is the error message we want to remove        if ( $errors[$i] == __( 'Please select the fields to be exported', 'gravityforms' ) ) {            unset( $errors[$i] );        }     }     return $errors;}
Source Code
This filter is located in GFCommon::display_admin_message() in common.php

gform_admin_messages

gform_admin_messages

DescriptionUsageParametersExamplesPlacementSource Code

Description
Modify update (and other non-error) messages displayed by Gravity Forms in the WordPress admin.
Usage
1add_action( 'gform_admin_messages', 'my_custom_function' );
Parameters

$messages array
An array of messages to be displayed below the title on Gravity Form pages.

Examples
This example demonstrates how we can append a 『Preview Form』 link to any update message where a form ID is available in the query string.
123456789101112131415161718add_action( 'gform_admin_messages', 'my_append_preview_form_link' );function my_append_preview_form_link( $messages ) {     // get the form ID from the query string    $form_id = rgget( 'id' );     // if no form ID is available, let's not add the 'Preview Form' link    if ( ! $form_id ) {        return;    }     // loop through our error messages and append the 'Preview Form' link    foreach ( $messages as &$message ) {        $message .= ' Preview Form';    }     return $messages;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::display_admin_message() in common.php

gform_admin_notification_attachments

gform_admin_notification_attachments

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter can be used to add attachments to the admin notification email.

This hook has been deprecated in v. 1.7. Please use gform_notification instead.

Usage
1add_filter( 'gform_admin_notification_attachments', 'add_attachment', 10, 3 );
You can also target a specific form by adding the form id after the hook name.
12//This filter declaration targets a form whose id is 6add_filter( 'gform_admin_notification_attachments_6', 'add_attachment', 10, 3 );

Parameters

$attachments string, array
The attachments to be filtered. It can be a simple strings containing for file path for one attachments or an array of strings for multiple attachments.

$entry Entry Object
Current entry object.

$form Form Object
Current form object.

Examples
This example attaches all file upload fields in the form to the admin notification email.
1234567891011121314151617add_filter( 'gform_admin_notification_attachments_4', 'add_attachment', 10, 3 );function add_attachment( $attachments, $lead, $form ) {    $fileupload_fields = GFCommon::get_fields_by_type( $form, array( 'fileupload' ) );    if ( ! is_array( $fileupload_fields ) ) {        return $attachments;    }    $attachments = array();    $upload_root = RGFormsModel::get_upload_root();    foreach ( $fileupload_fields as $field ) {        $url = $lead[ $field['id'] ];        $attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $url );        if ( $attachment ) {            $attachments[] = $attachment;        }    }    return $attachments;}
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_admin_pre_render

gform_admin_pre_render

DescriptionUsageParametersExamples1. Populate a choice based field.2. Enable entry meta in feed conditional logicPlacementSource Code

Description
This filter is executed before the entry detail is displayed and can be used to manipulate the Form Object prior to rendering the entry.
Usage
Applies to all forms
add_action( 'gform_admin_pre_render', 'pre_render_function' );

Applies to a specific form. In this case, form Id 5
add_action( 'gform_admin_pre_render_5', 'pre_render_function' );

Parameters

$form Form Object
The current form to be filtered.

Examples
1. Populate a choice based field.
This example dynamically populates a drop down field with posts that are in the Business category.
add_filter( 'gform_admin_pre_render', 'populate_dropdown' );
function populate_dropdown( $form ) {

//only populating drop down for form id 5
if ( $form['id'] != 5 )
return $form;

//Reading posts for "Business" category;
$posts = get_posts( 'category=Business' );

//Creating drop down item array.
$items = array();

//Adding initial blank value.
$items[] = array( 'text' => '', "value" => '' );

//Adding post titles to the items array
foreach ( $posts as $post )
$items[] = array( 'value' => $post->post_title, 'text' => $post->post_title );

//Adding items to field id 8. Replace 8 with your actual field id. You can get the field id by looking at the input name in the markup.
foreach ( $form['fields'] as &$field ) {
if ( $field->id == 8 ) {
$field->choices = $items;
}
}

return $form;
}

2. Enable entry meta in feed conditional logic
This example shows how entry meta, such as the quiz score, can be enabled for use when configuring conditional logic rules on the ActiveCampaign feed.
add_filter( 'gform_admin_pre_render', function ( $form ) {
if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && rgget( 'subview' ) == 'gravityformsactivecampaign' ) {
echo "';
}

return $form;
} );

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:

GFEntryDetail::lead_detail_page() in entry_detail.php
GFEntryDetail::lead_detail_edit() in entry_detail.php
GFFormDetail::forms_page() in form_detail.php
GFFormSettings::form_settings_ui() in form_settings.php
GFFormSettings::confirmations_edit_page() in form_settings.php
GFNotification::get_notification_ui_settings() in notification.php

gform_advanced_settings

gform_advanced_settings

DescriptionUsageParametersExamplesSource Code

Description
Use this filter to create a new form setting under the Properties tab. Useful when implementing a new setting that applies to the form rather than a specific field.

This hook has been deprecated. Please use gform_form_settings instead.

Usage
1add_action( 'gform_advanced_settings', 'my_form_advanced_settings', 10, 2 );

Parameters

$position integer
Specifies the position that the settings will be displayed. For a list of all available positions, search form_detail.php for 「gform_advanced_settings」.

$form_id integer
The ID of the current form.

Examples
This hook functions identically to the gform_field_advanced_settings hook. The only difference is the location of where the custom setting is output. gform_field_advanced_settings|Reference this example for usage.
Source Code
This filter is located in the following methods:

GFFormDetail::forms_page() in form_detail.php
GFFormSettings::form_settings_ui() in form_settings.php

gform_advancedpostcreation_args_pre_get_custom_post_types

gform_advancedpostcreation_args_pre_get_custom_post_types

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Enables the arguments used to get the custom post types to be overridden.
Usage
1add_filter( 'gform_advancedpostcreation_args_pre_get_custom_post_types', 'your_function_name', 10, 1 );

Parameters

$args array
The arguments to be used with the WP get_post_types function.

Examples
12345add_filter( 'gform_advancedpostcreation_args_pre_get_custom_post_types', 'set_args', 10, 1 );function set_args( $args ){    $args['public'] = false;    return $args;}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms Advanced Post Creation version 1.0-beta-2.4.
Source Code
This filter is located in GF_Advanced_Post_Creation::get_post_types_as_choices() in gravityformsadvancedpostcreation/class-gf-advancedpostcreation.php.

gform_advancedpostcreation_excerpt

gform_advancedpostcreation_excerpt

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Controls whether the post excerpt field is available in the feed settings.
Usage
1add_filter( 'gform_advancedpostcreation_excerpt', 'your_function_name', 10, 1 );

Parameters

$enable_excerpt bool
Controls whether the Post Excerpt setting is available. The default is false.

Examples
1234add_filter( 'gform_advancedpostcreation_excerpt', 'enable_excerpt', 10, 1 );function enable_excerpt( $enable_excerpt ){    return true;}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in the Gravity Forms Advanced Post Creation add-on version 1.0.
Source Code
This filter is located in GF_Advanced_Post_Creation::feed_settings_fields_create_post() in gf-class-advancedpostcreation.php.

gform_advancedpostcreation_file_fields_choices

gform_advancedpostcreation_file_fields_choices

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows the available choices for the media settings to be overridden on the feed configuration page.
Usage
add_filter( 'gform_advancedpostcreation_file_fields_choices', 'your_function_name', 10, 3 );

Parameters

$choices array
The file fields as choices.

$form Form Object
The current form.

$single_file bool
Indicates if only single file upload fields should be returned.

Examples
add_filter( 'gform_advancedpostcreation_file_fields_choices', 'filter_choices', 10, 3 );
function filter_choices( $choices, $form, $single_file ){
$filtered_choices = array();
foreach ( $choices as $choice )
{
if ($choice['label'] == 'Not For Media'){
continue;
}
$filtered_choices[] = $choice;
}
return $filtered_choices;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in the Gravity Forms Advanced Post Creation version 1.0-beta-2.2.
Source Code
This filter is located in GF_Advanced_Post_Creation::get_file_fields_as_choices() in gravityformsadvancedpostcreation/class-gf-advancedpostcreation.php.

gform_advancedpostcreation_post_after_creation

gform_advancedpostcreation_post_after_creation

DescriptionUsageParametersExamplesSend notification after post creationUpdate a post custom field with serialized GF checkboxesAdd Images to WooCommerce Product GalleryPlacementSinceSource Code

Description
Action hook which allows further actions to be performed after the post has been created.
Usage
The following would apply to all forms:
1add_action( 'gform_advancedpostcreation_post_after_creation', 'your_function_name', 10, 4 );
To target a specific form, append the form id to the hook name. (format: gform_advancedpostcreation_post_after_creation_FORMID):
1add_action( 'gform_advancedpostcreation_post_after_creation_1', 'your_function_name', 10, 4 );

Parameters

$post_id int
The new post id.

$feed Feed Object
The current feed object.

$entry Entry Object
The current entry object.

$form Form Object
The current form object.

Examples
Send notification after post creation
1234add_action( 'gform_advancedpostcreation_post_after_creation', 'after_post_creation', 10, 4 );function after_post_creation( $post_id, $feed, $entry, $form ){    GFCommon::send_email( '[email protected]', '[email protected]','','','New Post', 'A new post was created.');}
Update a post custom field with serialized GF checkboxes
This is useful for plugins like Advanced Custom Fields (ACF), Types and Pods where the values of the selections are stored in a serialized array. The scope of this example is limited to form id 1 and field id 18, you need to update these values to apply to your own form and field. Passing an array to update_post_meta will automatically serialize the array.
123456789101112131415161718192021add_action( 'gform_advancedpostcreation_post_after_creation_1', 'apc_serialize_checkboxes', 10, 4 );function apc_serialize_checkboxes( $post_id, $feed, $entry, $form ) {     // Checkboxes field id.    $field_id = 18;     // Get field object.    $field = GFAPI::get_field( $form, $field_id );      if ( $field->type == 'checkbox' ) {        // Get a comma separated list of checkboxes checked        $checked = $field->get_value_export( $entry );          // Convert to array.        $values = explode( ', ', $checked );      }     // Replace my_custom_field_key with your custom field meta key.    update_post_meta( $post_id, 'my_custom_field_key', $values );}
Add Images to WooCommerce Product Gallery
This code snippet can be used to add images added through File/Upload fields and mapped to the Product Post type in the Media Library. This will take any images attached to the post for the product and add them to the product gallery in WooCommerce.
12345678910111213// Add images to WooCommerce product gallery. Change 1909 on the following line to your form id number.add_action( 'gform_advancedpostcreation_post_after_creation_1909', 'apc_add_images_to_product_gallery', 10, 4 );function apc_add_images_to_product_gallery( $post_id, $feed, $entry, $form ) {    GFCommon::log_debug( __METHOD__ . '(): running.' );     $attached_images = get_attached_media( 'image', $post_id );    GFCommon::log_debug( __METHOD__ . '(): Images attached to Post: ' . print_r( $attached_images, true ) );    $product_gallery = implode( ',', array_keys( $attached_images ) );    GFCommon::log_debug( __METHOD__ . '(): Product gallery ID's: ' . $product_gallery );     // Add the meta key with the comma separated ID's for images attached to the post.    update_post_meta( $post_id, '_product_image_gallery', $product_gallery );}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms Advanced Post Creation add-on version 1.0.
Source Code
This filter is located in GF_Advanced_Post_Creation::create_post() in class-gf-advancedpostcreation.php.