9
9
* Plugin URI: https://gravitywiz.com/cache-busting-with-gravity-forms/
10
10
* Description: Bypass your website cache when loading a Gravity Forms form.
11
11
* Author: Gravity Wiz
12
- * Version: 0.2
12
+ * Version: 0.3
13
13
* Author URI: https://gravitywiz.com
14
14
*/
15
15
class GW_Cache_Buster {
@@ -135,17 +135,18 @@ public function shortcode( $markup, $attributes, $content ) {
135
135
</style>
136
136
</div>
137
137
<?php
138
- // Store current URL parameters and include them in AJAX call
139
- // This preserves dynamic form population
140
- $ params = array ();
141
- $ exclude_params = array ( 'action ' , 'form_id ' , 'atts ' ); // Exclude parameters that may clash
142
- foreach ( $ _GET as $ k => $ v ) {
143
- if ( ! in_array ( $ k , $ exclude_params , true ) ) {
144
- $ params [ $ k ] = sprintf ( '%s=%s ' , $ k , $ _GET [ $ k ] );
145
- }
146
- }
147
- $ params = ( count ( $ params ) > 0 ) ? '& ' . join ( '& ' , $ params ) : '' ;
148
- $ lang = null ;
138
+ // Include original query parameters (with some exclusions) in the AJAX call to preserve dynamic population via query string.
139
+ $ exclude_params = array ( 'action ' , 'form_id ' , 'atts ' );
140
+ $ ajax_url = remove_query_arg ( $ exclude_params , add_query_arg ( $ _GET , admin_url ( 'admin-ajax.php ' ) ) );
141
+ $ ajax_url = add_query_arg (
142
+ array (
143
+ 'action ' => 'gfcb_get_form ' ,
144
+ 'form_id ' => $ form_id
145
+ ),
146
+ $ ajax_url
147
+ );
148
+
149
+ $ lang = null ;
149
150
if ( class_exists ( 'Gravity_Forms_Multilingual ' ) ) {
150
151
global $ sitepress ;
151
152
$ lang = $ sitepress ->get_current_language ();
@@ -154,7 +155,7 @@ public function shortcode( $markup, $attributes, $content ) {
154
155
<script type="text/javascript">
155
156
( function ( $ ) {
156
157
var formId = '<?php echo $ form_id ; ?> ';
157
- $.post( '<?php echo admin_url ( ' admin-ajax.php ' ); ?> ?action=gfcb_get_form&form_id= <?php echo $ form_id , $ params ; ?> ', {
158
+ $.post( '<?php echo $ ajax_url ; ?> ', {
158
159
action: 'gfcb_get_form',
159
160
form_id: '<?php echo $ form_id ; ?> ',
160
161
atts: '<?php echo json_encode ( $ attributes ); ?> ',
@@ -175,8 +176,7 @@ public function shortcode( $markup, $attributes, $content ) {
175
176
// Form has been rendered. Trigger post render to initialize scripts.
176
177
jQuery( document ).trigger( 'gform_post_render', [ formId, 1 ] );
177
178
} );
178
- } );
179
- } ( jQuery ) );
179
+ } ) ( jQuery);
180
180
</script>
181
181
182
182
<?php
0 commit comments