Skip to content

Commit

Permalink
gw-cache-buster.php: Fixed issue where $script was sometimes und…
Browse files Browse the repository at this point in the history
…efined when wrapping in `gform_post_render`.
  • Loading branch information
veryspry committed Aug 25, 2023
1 parent a9931fa commit 71bb1f8
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions gravity-forms/gw-cache-buster.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,27 @@ public function ajax_get_form() {
* event is triggered. Otherwise, the perk's init scripts will run before the form is loaded into the DOM.
*/
public function wrap_perk_scripts_in_gform_post_render( $form, $is_ajax ) {
if ( class_exists( 'GP_Nested_Forms' ) ) {
$key = 'gpnf_init_script_' . GFFormDisplay::ON_PAGE_RENDER;
$script = GFFormDisplay::$init_scripts[ $form['id'] ][ $key ]['script'];
$perks = array(
array(
'perk_class' => 'GP_Nested_Forms',
'key' => 'gpnf_init_script_' . GFFormDisplay::ON_PAGE_RENDER,
),
array(
'perk_class' => 'GP_Advanced_Save_And_Continue',
'key' => 'gp_advanced_save_and_continue_' . $form['id'] . '_' . GFFormDisplay::ON_PAGE_RENDER,
)

Check failure on line 247 in gravity-forms/gw-cache-buster.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Each array item in a multi-line array declaration must end in a comma
);

foreach ( $perks as $perk ) {
$script = rgars( GFFormDisplay::$init_scripts, "{$form['id']}/{$perk['key']}/script" );

if ( ! class_exists( $perk['perk_class'] ) || ! $script ) {
continue;
}

$script = 'jQuery( document ).on( "gform_post_render", function() { ' . $script . ' } );';
GFFormDisplay::$init_scripts[ $form['id'] ][ $key ]['script'] = $script;
}

if ( class_exists( 'GP_Advanced_Save_And_Continue' ) ) {
$key = 'gp_advanced_save_and_continue_' . $form['id'] . '_' . GFFormDisplay::ON_PAGE_RENDER;
$script = GFFormDisplay::$init_scripts[ $form['id'] ][ $key ]['script'];
$script = 'jQuery( document ).on( "gform_post_render", function() { ' . $script . ';console.log("supp brother....");' . ' } );';
GFFormDisplay::$init_scripts[ $form['id'] ][ $key ]['script'] = $script;
GFFormDisplay::$init_scripts[ $form['id'] ][ $perk['key'] ]['script'] = $script;
}
}

Expand Down

0 comments on commit 71bb1f8

Please sign in to comment.