Insert Pages - Version 3.2.9

Version Description

  • Add querystring parameter to the shortcode to pass custom querystring values to any custom templates.

Example: [insert page='your-page' display='your-custom-template.php' querystring='foo=bar&baz=qux']

Note: If you need to use arrays in your querystring variables, use braces {} instead of brackets [], since WordPress shortcodes cannot have brackets inside them. The plugin will convert the braces internally. Example: querystring='foo[]=bar&foo[]=baz'

Download this release

Release Info

Developer figureone
Plugin Icon wp plugin Insert Pages
Version 3.2.9
Comparing to
See all releases

Code changes from version 3.2.8 to 3.2.9

Files changed (4) hide show
  1. css/wpinsertpages.css +1 -1
  2. insert-pages.php +33 -1
  3. js/wpinsertpages.js +22 -3
  4. readme.txt +7 -0
css/wpinsertpages.css CHANGED
@@ -40,7 +40,7 @@
40
  }
41
 
42
  #wp-insertpage-wrap.options-panel-visible {
43
- height: 500px;
44
  margin-top: -250px;
45
  }
46
 
40
  }
41
 
42
  #wp-insertpage-wrap.options-panel-visible {
43
+ height: 525px;
44
  margin-top: -250px;
45
  }
46
 
insert-pages.php CHANGED
@@ -9,7 +9,7 @@ Author URI: http://www.linkedin.com/in/paulrryan
9
  Text Domain: insert-pages
10
  Domain Path: /languages
11
  License: GPL2
12
- Version: 3.2.8
13
  */
14
 
15
  /* Copyright 2011 Paul Ryan (email: prar@hawaii.edu)
@@ -121,6 +121,7 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
121
  'display' => 'all',
122
  'class' => '',
123
  'inline' => false,
 
124
  ), $atts, 'insert' );
125
 
126
  // Validation checks.
@@ -151,6 +152,19 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
151
  $attributes['inline'] = apply_filters( 'insert_pages_use_inline_wrapper', $attributes['inline'] );
152
  $attributes['wrapper_tag'] = $attributes['inline'] ? 'span' : 'div';
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  $attributes['should_apply_the_content_filter'] = true;
155
  /**
156
  * Filter the flag indicating whether to apply the_content filter to post
@@ -231,6 +245,15 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
231
  $inserted_page = get_post( intval( $attributes['page'] ) );
232
  }
233
 
 
 
 
 
 
 
 
 
 
234
  // Use "Normal" insert method (get_post()).
235
  if ( $options['wpip_insert_method'] !== 'legacy' ) {
236
 
@@ -563,12 +586,17 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
563
  * display: Content to display from inserted page.
564
  * class: Extra classes to add to inserted page wrapper element.
565
  * inline: Boolean indicating wrapper element should be a span.
 
566
  * should_apply_nesting_check: Whether to disable nested inserted pages.
567
  * should_apply_the_content_filter: Whether to apply the_content filter to post contents and excerpts.
568
  * wrapper_tag: Tag to use for the wrapper element (e.g., div, span).
569
  */
570
  $content = apply_filters( 'insert_pages_wrap_content', $content, $inserted_page, $attributes );
571
 
 
 
 
 
572
  return $content;
573
  }
574
 
@@ -732,6 +760,10 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
732
  <?php _e( 'Inline?', 'insert-pages' ); ?>
733
  <input id="insertpage-extra-inline" type="checkbox" />
734
  </label>
 
 
 
 
735
  </div>
736
  </div>
737
  </div>
9
  Text Domain: insert-pages
10
  Domain Path: /languages
11
  License: GPL2
12
+ Version: 3.2.9
13
  */
14
 
15
  /* Copyright 2011 Paul Ryan (email: prar@hawaii.edu)
121
  'display' => 'all',
122
  'class' => '',
123
  'inline' => false,
124
+ 'querystring' => '',
125
  ), $atts, 'insert' );
126
 
127
  // Validation checks.
152
  $attributes['inline'] = apply_filters( 'insert_pages_use_inline_wrapper', $attributes['inline'] );
153
  $attributes['wrapper_tag'] = $attributes['inline'] ? 'span' : 'div';
154
 
155
+ /**
156
+ * Filter the querystring values applied to every inserted page. Useful
157
+ * for admins who want to provide the same querystring value to all
158
+ * inserted pages sitewide.
159
+ *
160
+ * @since 3.2.9
161
+ *
162
+ * @param string $querystring The querystring value for the inserted page.
163
+ */
164
+ $attributes['querystring'] = apply_filters( 'insert_pages_override_querystring',
165
+ str_replace( '{', '[', str_replace( '}', ']', htmlspecialchars_decode( $attributes['querystring'] ) ) )
166
+ );
167
+
168
  $attributes['should_apply_the_content_filter'] = true;
169
  /**
170
  * Filter the flag indicating whether to apply the_content filter to post
245
  $inserted_page = get_post( intval( $attributes['page'] ) );
246
  }
247
 
248
+ // Set any querystring params included in the shortcode.
249
+ parse_str( $attributes['querystring'], $querystring );
250
+ $original_get = $_GET;
251
+ $original_request = $_REQUEST;
252
+ foreach ( $querystring as $param => $value ) {
253
+ $_GET[$param] = $value;
254
+ $_REQUEST[$param] = $value;
255
+ }
256
+
257
  // Use "Normal" insert method (get_post()).
258
  if ( $options['wpip_insert_method'] !== 'legacy' ) {
259
 
586
  * display: Content to display from inserted page.
587
  * class: Extra classes to add to inserted page wrapper element.
588
  * inline: Boolean indicating wrapper element should be a span.
589
+ * querystring: Extra querystring values provided to the custom template.
590
  * should_apply_nesting_check: Whether to disable nested inserted pages.
591
  * should_apply_the_content_filter: Whether to apply the_content filter to post contents and excerpts.
592
  * wrapper_tag: Tag to use for the wrapper element (e.g., div, span).
593
  */
594
  $content = apply_filters( 'insert_pages_wrap_content', $content, $inserted_page, $attributes );
595
 
596
+ // Unset any querystring params included in the shortcode.
597
+ $_GET = $original_get;
598
+ $_REQUEST = $original_request;
599
+
600
  return $content;
601
  }
602
 
760
  <?php _e( 'Inline?', 'insert-pages' ); ?>
761
  <input id="insertpage-extra-inline" type="checkbox" />
762
  </label>
763
+ <label for="insertpage-extra-querystring">
764
+ <?php _e( 'Querystring', 'insert-pages' ); ?>
765
+ <input id="insertpage-extra-querystring" type="text" autocomplete="off" />
766
+ </label>
767
  </div>
768
  </div>
769
  </div>
js/wpinsertpages.js CHANGED
@@ -28,6 +28,7 @@ var wpInsertPages;
28
  // Extra fields (wrapper classes, inline checkbox)
29
  inputs.extraClasses = $( '#insertpage-extra-classes' );
30
  inputs.extraInline = $( '#insertpage-extra-inline' );
 
31
  // Custom template select field
32
  inputs.template = $( '#insertpage-template-select' );
33
  inputs.search = $( '#insertpage-search-field' );
@@ -111,7 +112,8 @@ var wpInsertPages;
111
  // Get cursor state (used later to determine if we're in an existing shortcode)
112
  node = editor.selection.getNode();
113
  bookmark = editor.selection.getBookmark( 0 );
114
- cursorPosition = node.innerHTML.indexOf( '<span data-mce-type="bookmark"' );
 
115
  editor.selection.moveToBookmark( bookmark );
116
 
117
  } else {
@@ -163,7 +165,7 @@ var wpInsertPages;
163
 
164
  // Get the existing shortcode the cursor is in (or get the entire node if cursor not in one)
165
  shortcode = '';
166
- content = editor.selection.getNode().innerHTML;
167
  if ( content.indexOf( '[insert page=' ) >= 0 ) {
168
  // Find occurrences of shortcode in current node and see if the cursor
169
  // position is inside one of them.
@@ -187,7 +189,8 @@ var wpInsertPages;
187
  offset = 0;
188
  for ( i = 0; i < node.childNodes.length; i++ ) {
189
  selectedChild = node.childNodes[i];
190
- length = ( selectedChild.outerHTML ) ? selectedChild.outerHTML.length : selectedChild.textContent.length;
 
191
  if ( cursorPosition <= offset + length ) {
192
  break;
193
  }
@@ -247,6 +250,17 @@ var wpInsertPages;
247
  inputs.extraInline.attr( 'checked', false );
248
  }
249
 
 
 
 
 
 
 
 
 
 
 
 
250
  // Update save prompt.
251
  inputs.submit.val( wpInsertPagesL10n.update );
252
 
@@ -294,6 +308,7 @@ var wpInsertPages;
294
  display: inputs.format.val()=='template' ? inputs.template.val() : inputs.format.val(),
295
  class: inputs.extraClasses.val(),
296
  inline: inputs.extraInline.is( ':checked' ),
 
297
  };
298
  },
299
 
@@ -325,6 +340,10 @@ var wpInsertPages;
325
  "display='" + attrs.display + "'" +
326
  ( attrs['class'].length > 0 ? " class='" + attrs['class'] + "'" : "" ) +
327
  ( attrs.inline ? " inline" : "" ) +
 
 
 
 
328
  "]");
329
  editor.execCommand("mceEndUndoLevel");
330
  },
28
  // Extra fields (wrapper classes, inline checkbox)
29
  inputs.extraClasses = $( '#insertpage-extra-classes' );
30
  inputs.extraInline = $( '#insertpage-extra-inline' );
31
+ inputs.extraQuerystring = $( '#insertpage-extra-querystring' );
32
  // Custom template select field
33
  inputs.template = $( '#insertpage-template-select' );
34
  inputs.search = $( '#insertpage-search-field' );
112
  // Get cursor state (used later to determine if we're in an existing shortcode)
113
  node = editor.selection.getNode();
114
  bookmark = editor.selection.getBookmark( 0 );
115
+ unencodedText = node.innerHTML.replace( /&amp;/g, '&' );
116
+ cursorPosition = unencodedText.indexOf( '<span data-mce-type="bookmark"' );
117
  editor.selection.moveToBookmark( bookmark );
118
 
119
  } else {
165
 
166
  // Get the existing shortcode the cursor is in (or get the entire node if cursor not in one)
167
  shortcode = '';
168
+ content = editor.selection.getNode().innerHTML.replace( /&amp;/g, '&' );
169
  if ( content.indexOf( '[insert page=' ) >= 0 ) {
170
  // Find occurrences of shortcode in current node and see if the cursor
171
  // position is inside one of them.
189
  offset = 0;
190
  for ( i = 0; i < node.childNodes.length; i++ ) {
191
  selectedChild = node.childNodes[i];
192
+ text = ( selectedChild.outerHTML ) ? selectedChild.outerHTML : selectedChild.textContent;
193
+ length = text.length;
194
  if ( cursorPosition <= offset + length ) {
195
  break;
196
  }
250
  inputs.extraInline.attr( 'checked', false );
251
  }
252
 
253
+ // Update extra querystring.
254
+ regexp = /querystring=['"]([^['"]*)['"]/;
255
+ matches = regexp.exec( shortcode );
256
+ if ( matches && matches.length > 1 ) {
257
+ // Also unescape brackets in the querystring (if left alone, any
258
+ // closing bracket will terminate the shortcode).
259
+ inputs.extraQuerystring.val( matches[1].replace( /&amp;/g, '&' ) );
260
+ } else {
261
+ inputs.extraQuerystring.val( '' );
262
+ }
263
+
264
  // Update save prompt.
265
  inputs.submit.val( wpInsertPagesL10n.update );
266
 
308
  display: inputs.format.val()=='template' ? inputs.template.val() : inputs.format.val(),
309
  class: inputs.extraClasses.val(),
310
  inline: inputs.extraInline.is( ':checked' ),
311
+ querystring: inputs.extraQuerystring.val(),
312
  };
313
  },
314
 
340
  "display='" + attrs.display + "'" +
341
  ( attrs['class'].length > 0 ? " class='" + attrs['class'] + "'" : "" ) +
342
  ( attrs.inline ? " inline" : "" ) +
343
+ ( attrs.querystring ? " querystring='" +
344
+ attrs['querystring'].replace( /&/g, '&amp;' ).replace( /\[/g, '{' ).replace( /\]/g, '}' )
345
+ + "'" : ""
346
+ ) +
347
  "]");
348
  editor.execCommand("mceEndUndoLevel");
349
  },
readme.txt CHANGED
@@ -86,6 +86,13 @@ Just one! The plugin prevents you from embedding a page in itself, but you can t
86
 
87
  == Changelog ==
88
 
 
 
 
 
 
 
 
89
  = 3.2.8 =
90
  * Add support for inserting pages/posts built with Elementor.
91
 
86
 
87
  == Changelog ==
88
 
89
+ = 3.2.9 =
90
+ * Add querystring parameter to the shortcode to pass custom querystring values to any custom templates.
91
+
92
+ Example: [insert page='your-page' display='your-custom-template.php' querystring='foo=bar&baz=qux']
93
+
94
+ Note: If you need to use arrays in your querystring variables, use braces {} instead of brackets [], since WordPress shortcodes cannot have brackets inside them. The plugin will convert the braces internally. Example: querystring='foo[]=bar&foo[]=baz'
95
+
96
  = 3.2.8 =
97
  * Add support for inserting pages/posts built with Elementor.
98