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.