Last active
July 29, 2020 06:50
-
-
Save zackkatz/e25cddf3abe9edc856f5ec83df1a4ec7 to your computer and use it in GitHub Desktop.
GravityView - Clears results cache after running Gravity Flow workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add the code below to your functions.php file. Will be included in GravityView 2.9 release. | |
add_action( 'gravityflow_post_process_workflow', 'gv_clear_cache_after_workflow', 10, 4 ); | |
/** | |
* Clears GravityView entry cache after running a Gravity Flow Workflow | |
* | |
* Thanks to @CodenomadIndia for improved code! | |
* | |
* @param array $form | |
* @param int $entry_id | |
* @param int $step_id | |
* @param int $starting_step_id | |
* | |
* @return void | |
*/ | |
public function gv_clear_cache_after_workflow( $form, $entry_id, $step_id, $starting_step_id ) { | |
$step = gravity_flow()->get_step( $step_id ); | |
// Check if the step type is updating an entry | |
if( ! $step || 'update_entry' !== $step->get_type() ) { | |
return; | |
} | |
// Clear cache of the step target's form id | |
do_action( 'gravityview_clear_form_cache', $step->target_form_id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Zack,
If the Gravity Flow is used to update another form entry, the use the below code to clear cache of the updated form:
`<?php
// Add the code below to your functions.php file. Will be included in GravityView 2.9 release.
add_action( 'gravityflow_post_process_workflow', 'gv_clear_cache_after_workflow', 10, 4 );
/**
*/
public function gv_clear_cache_after_workflow( $form, $entry_id, $step_id, $starting_step_id ) {
$api = new Gravity_Flow_API( $form['id'] );
$step = $api->get_step($step_id);
if($step->_step_type == "update_entry"){ // Check if the step type is updating an entry
$update_form_id = $step->target_form_id; // get the target form id from the step
do_action( 'gravityview_clear_form_cache', $update_form_id ); //clear cache of the target form id
}
}`