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_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_advancedpostcreation_update_post_data

gform_advancedpostcreation_update_post_data

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description

Allows modifying the post data before updating it.

Usage

The following would apply to all forms:

add_filter( 'gform_advancedpostcreation_update_post_data', 'your_function_name', 10, 3 );

To target a specific form, append the form id to the hook name. (format: gform_advancedpostcreation_update_post_data_FORMID)

add_filter( 'gform_advancedpostcreation_update_post_data_1', 'your_function_name', 10, 3 );

Parameters

$post arrayThe post array being updated. Array returned is the WP get_post function.$feed Feed ObjectThe feed being processed.$entry Entry ObjectThe entry linked to the post.

Examples

add_filter( 'gform_advancedpostcreation_update_post_data', 'your_update_post_data', 10, 3 );
function your_update_post_data ($post, $feed, $entry) {
// do something
}

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_AdvancedPost_Creation::update() in class-post-update-handler.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_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_after_check_update

gform_after_check_update

DescriptionUsageParametersExamplesSource Code

Description
Runs a function after Gravity Forms has checked for an update.
Usage
add_action( 'gform_after_check_update', 'my_function', 10, 0 );

Parameters
There are not any parameters for this action.

Examples
function my_function() {
echo 'Update was checked';
}
add_action( 'gform_after_check_update', 'my_function', 10, 0 );

Source Code
This action hook is located in update.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_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_after_create_post

gform_after_create_post

DescriptionUsageParametersExamples1. Update the post2. Convert date to the format expected by an ACF datepicker field type3. Update a post custom field with serialized GF checkboxesPlacementSource CodeSince

Description
This action hook is executed after the post has been created. It only applies to forms that have Post Fields.
Usage
The following would apply to all forms.
add_action( 'gform_after_create_post', 'your_function_name' );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_after_create_post_FORMID)
add_action( 'gform_after_create_post_6', 'your_function_name' );

Parameters

$post_id integer
The ID of the post which was created from the form submission.

$entry Entry Object
The entry currently being processed. Available from 1.9.13.

$form Form Object
The form currently being processed. Available from 1.9.13.

Examples
1. Update the post
This example shows how you can update the post content, adding values from submitted fields, including an image field.
add_action( 'gform_after_create_post', 'set_post_content', 10, 3 );
function set_post_content( $post_id, $entry, $form ) {

//getting post
$post = get_post( $post_id );

//changing post content
$post->post_content = 'Blender Version:' . rgar( $entry, '7' ) . "

" . rgar( $entry, '13' ) . "
";

//updating post
wp_update_post( $post );
}

2. Convert date to the format expected by an ACF datepicker field type
The example below would take the date saved for a Gravity Forms field with id 30, convert it to the format expected by the ACF datepicker field type, and save it to the custom field meta key acf_date
Make sure to update the field id, the custom field meta key, and the form id number to make it work. Please read the snippet comments.
// Change 12 below to your form id number.
add_action( 'gform_after_create_post_12', 'gf_date_to_acf', 10, 3 );
function gf_date_to_acf( $post_id, $entry, $form ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
// Date as saved by GF. Change 30 to your date field id number.
$gf_date = rgar( $entry, '30' );
// Date changed to format expected by ACF.
$acf_date = date( 'Ymd', strtotime( $gf_date ) );
GFCommon::log_debug( __METHOD__ . '(): Date for ACF: ' . $acf_date );
// Save converted date to the acf_date meta key. Change it to your custom field meta key.
update_post_meta( $post_id, 'acf_date', $acf_date );
}

3. 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.
// Change 1 in gform_after_create_post_1 to your form id number.
add_filter( 'gform_after_create_post_1', 'gf_post_acf_checkboxes', 10, 3 );
function gf_post_acf_checkboxes( $post_id, $entry, $form ) {

// Checkboxes field id. Change this value to your field id number.
$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', $value );
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
gf_do_action( 'gform_after_create_post', $form['id'], $post_id, $lead, $form )
This hook is located in GFFormsModel::create_post() in forms_model.php.
Since
The form specific version of this hook was added in Gravity Forms 1.9.13.

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.