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_term_separator

gform_advancedpostcreation_term_separator

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Filters the separator character used when separating term names.
Usage
add_filter( 'gform_advancedpostcreation_term_separator', 'your_function_name', 10, 1 );

Parameters

$separator string
The separator to be filtered.

Examples
add_filter( 'gform_advancedpostcreation_term_separator', 'set_separator', 10, 1 );
function set_separator( $separator ){
return '|';
}

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.5.
Source Code
This filter is located in GF_Advanced_Post_Creation::get_mapped_taxonomies() in gravityformsadvancedpostcreation/class-gf-advancedpostcreation.php.

gform_advancedpostcreation_pre_update_post

gform_advancedpostcreation_pre_update_post

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description

Allow custom actions to be performed before the post is updated.

Usage

The following would apply to all forms:

add_action( 'gform_advancedpostcreation_pre_update_post', 'your_function_name', 10, 3 );

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

add_action( 'gform_advancedpostcreation_pre_update_post_1', 'your_function_name', 10, 3 );

Parameters

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

Examples

add_action( 'gform_advancedpostcreation_pre_update_post', 'pre_update_your_post', 10, 3 );
function pre_update_your_post ($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 Gravity Forms Advanced Post Creation add-on version 1.0

Source Code

This filter is located in GF_Advanced_Post_Creation:update() in class-post-update-handler.php

gform_advancedpostcreation_post

gform_advancedpostcreation_post

DescriptionUsageParametersExamplesChange the post contentChange the post slugChange the post excerptPlacementSinceSource Code

Description

Modifies the Post object before it is created.

Note: This filter should not be used to override the Post ID value. Doing it would cause unexpected results during the Post creation process.

Usage

The following would apply to all forms:

add_filter( 'gform_advancedpostcreation_post', 'your_function_name', 10, 4 );

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

add_filter( 'gform_advancedpostcreation_post_1', 'your_function_name', 10, 4 );

Parameters

$post boolThe post object to be created.

Array
(
[post_status] => publish
[post_type] => post
[post_title] => testing
[comment_status] => closed
[ping_status] => closed
[ID] => 328
[post_content] => test,test, test, test,
[post_excerpt] => Excerpt Test
[post_author] => 1
[post_date_gmt] => 2019-04-30 20:40:00
)

$feed Feed ObjectThe current feed object.$entry Entry ObjectThe current entry object.$form Form ObjectThe current form object.

Examples

Change the post content

add_filter( 'gform_advancedpostcreation_post', 'change_post', 10, 4 );
function change_post( $post, $feed, $entry, $form){
$post['post_content'] = 'This is a test';
return $post;
}

Change the post slug

This example uses merge tags to change the post slug which is taken from the post_name property. This time we have limited the scope of the snippet to form id 1 by adding the form id to the filter name.

add_filter( 'gform_advancedpostcreation_post_1', function ( $post, $feed, $entry, $form ) {
$slug = '{first name:1.3} {last name:1.6} {date:2:year}-{date:2:month}';
$post['post_name'] = sanitize_title( GFCommon::replace_variables( $slug, $form, $entry, false, false, false, 'text' ) );
return $post;
}, 10, 4 );

Change the post excerpt

This examples uses a specific paragraph field to be written to the post excerpt. Be sure to change your code to match the field id which you are using for inputting the excerpt.

add_filter( 'gform_advancedpostcreation_post', 'change_post_excerpt', 10, 4 );
function change_post_excerpt( $post, $feed, $entry, $form){
$post['post_excerpt'] = rgar( $entry, 6 ); // Field 6 is the Excerpt
return $post;
}

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::create_post() in 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.

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