Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Last active July 29, 2020 06:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackkatz/e25cddf3abe9edc856f5ec83df1a4ec7 to your computer and use it in GitHub Desktop.
Save zackkatz/e25cddf3abe9edc856f5ec83df1a4ec7 to your computer and use it in GitHub Desktop.
GravityView - Clears results cache after running Gravity Flow workflow
<?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 );
}
@CodenomadIndia
Copy link

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 );

/**

  • Clears GravityView entry cache after running a Gravity Flow Workflow
  • @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 ) {
    $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
    }
    }`

@zackkatz
Copy link
Author

zackkatz commented Jul 7, 2020

Thanks @CodenomadIndia! I've updated the sample.

@CodenomadIndia
Copy link

CodenomadIndia commented Jul 7, 2020

Thanks @zackkatz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment