Description
The gravityflow_post_webhook action fires after the webhook request providing a way to customize the response before it is sent back to the requesting server.
Parameters
Parameter | Type | Details |
---|---|---|
$response | Array | The response returned from webhook. |
$args | Array | The arguments used for executing the webhook request. |
$entry | Entry | The current entry. |
$step | Step | The current step. |
Examples
Convert a get request of a file into a local file and store in a file upload field
add_action( 'gravityflow_post_webhook', 'jo_action_gravityflow_post_webhook', 10, 4 );
function jo_action_gravityflow_post_webhook( $response, $args, $entry, $current_step ) {
//Ensure it only executes on our desired step.
if( $current_step->get_id() !== '83' ) {
return;
}
//Ensure the response is a valid scenario for processing
if ( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && $response['response']['code'] == 200 && isset( $response['body'] ) ) {
//Define where we will be retrieving the file to.
$folder = '/tmp-pdf/';
$filename = 'product-entry-' . $entry['id'] . '.pdf';<br> $field_id = '2';
$upload_dir = wp_upload_dir();
//Store the PDF to uploads directory
file_put_contents( $upload_dir['basedir'] . $folder . $filename, $response['body'] );
//Update the entry upload field with URL to file.
GFAPI::update_entry_field( $entry['id'], $field_id, $upload_dir['baseurl'] . $folder . $filename );
}
}
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?