@@ -16,6 +16,8 @@ class GW_Cache_Buster {
1616
1717 private $ _args = array ();
1818
19+ private $ _form_args = array ();
20+
1921 public function __construct ( $ args = array () ) {
2022
2123 // set our default arguments, parse against the provided arguments, and store for use throughout the class
@@ -40,6 +42,8 @@ public function init() {
4042 }
4143
4244 add_filter ( 'gform_shortcode_form ' , array ( $ this , 'shortcode ' ), 10 , 3 );
45+ add_filter ( 'gform_get_form_filter ' , array ( $ this , 'form_filter ' ), 10 , 2 );
46+ add_filter ( 'gform_form_args ' , array ( $ this , 'stash_form_args ' ) );
4347 add_filter ( 'gform_save_and_continue_resume_url ' , array ( $ this , 'filter_resume_link ' ), 15 , 4 );
4448 add_filter ( 'gform_pre_replace_merge_tags ' , array ( $ this , 'replace_embed_url ' ), 10 , 4 );
4549 add_action ( 'gform_after_submission ' , array ( $ this , 'entry_source_url ' ), 10 , 2 );
@@ -73,11 +77,16 @@ public function set_form_styles( $form, $style_settings, $form_theme ) {
7377 }
7478 $ form ['styles ' ] = GFFormDisplay::get_form_styles ( $ form_styles );
7579 $ form ['theme ' ] = $ form_theme ;
80+
7681 return $ form ;
7782 }
7883
79- public function shortcode ( $ markup , $ attributes , $ content ) {
84+ public function stash_form_args ( $ form_args ) {
85+ $ this ->_form_args [ $ form_args ['form_id ' ] ] = $ form_args ;
86+ return $ form_args ;
87+ }
8088
89+ public function shortcode ( $ markup , $ attributes , $ content ) {
8190 $ atts = shortcode_atts (
8291 array (
8392 'id ' => 0 ,
@@ -90,6 +99,33 @@ public function shortcode( $markup, $attributes, $content ) {
9099 $ attributes
91100 );
92101
102+ remove_filter ( 'gform_get_form_filter ' , array ( $ this , 'form_filter ' ), 10 , 2 );
103+ return $ this ->get_cachebuster_markup ( $ markup , array_merge ( $ attributes , $ atts ), $ content );
104+ }
105+
106+ public function form_filter ( $ markup , $ form ) {
107+ // Prevent recursion.
108+ if ( rgar ( $ GLOBALS , 'processing ' ) ) {
109+ return $ markup ;
110+ }
111+
112+ $ form_args = rgar ( $ this ->_form_args , $ form ['id ' ] );
113+ $ atts = array (
114+ 'id ' => $ form ['id ' ],
115+ 'cachebuster ' => true ,
116+ 'title ' => $ form_args ['display_title ' ],
117+ 'description ' => $ form_args ['display_description ' ],
118+ 'field_values ' => $ form_args ['field_values ' ],
119+ 'ajax ' => $ form_args ['ajax ' ],
120+ 'tabindex ' => $ form_args ['tabindex ' ]
121+ 'theme ' => rgar ( $ form , 'theme ' ),
122+ 'styles ' => rgar ( $ form , 'styles ' ),
123+ );
124+
125+ return $ this ->get_cachebuster_markup ( $ markup , $ atts , null );
126+ }
127+
128+ public function get_cachebuster_markup ( $ markup , $ atts , $ content ) {
93129 $ form_id = $ atts ['id ' ];
94130
95131 if ( ! $ this ->is_cache_busting_applicable () ) {
@@ -210,7 +246,7 @@ public function shortcode( $markup, $attributes, $content ) {
210246 $.post( '<?php echo $ ajax_url ; ?> ', {
211247 action: 'gfcb_get_form',
212248 form_id: '<?php echo $ form_id ; ?> ',
213- atts: <?php echo wp_json_encode ( $ attributes ); ?> ,
249+ atts: <?php echo wp_json_encode ( $ atts ); ?> ,
214250 form_request_origin: '<?php echo esc_js ( GFCommon::openssl_encrypt ( GFFormsModel::get_current_page_url () ) ); ?> ',
215251 lang: '<?php echo $ lang ; ?> '
216252 }, function( response ) {
@@ -310,7 +346,9 @@ public function ajax_get_form() {
310346 $ GLOBALS ['GWCB_POST ' ] = $ _POST ;
311347 $ _POST = array ();
312348
349+ $ GLOBALS ['processing ' ] = true ;
313350 gravity_form ( $ form_id , filter_var ( rgar ( $ atts , 'title ' , true ), FILTER_VALIDATE_BOOLEAN ), filter_var ( rgar ( $ atts , 'description ' , true ), FILTER_VALIDATE_BOOLEAN ), false , $ field_values , true /* default to true; add support for non-ajax in the future */ , rgar ( $ atts , 'tabindex ' ) );
351+ $ GLOBALS ['processing ' ] = false ;
314352
315353 remove_filter ( 'gform_form_tag_ ' . $ form_id , array ( $ this , 'add_hidden_inputs ' ) );
316354 remove_filter ( 'gform_pre_render_ ' . $ form_id , array ( $ this , 'replace_embed_tag_for_field_default_values ' ) );
0 commit comments