Insert Pages - Version 3.4.2

Version Description

  • Add 'public' shortcode param that lets private inserted pages be visible to anonymous users. Props @ahtcx for the suggestion.
  • Fix for inserted pages shown on BuddyPress profiles. Props @IdleWanderer for the report!
  • Fix for querystring option missing from widget settings.
Download this release

Release Info

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

Code changes from version 3.4.1 to 3.4.2

Files changed (5) hide show
  1. css/wpinsertpages.css +3 -3
  2. insert-pages.php +29 -7
  3. js/wpinsertpages.js +17 -3
  4. readme.txt +5 -0
  5. widget.php +18 -0
css/wpinsertpages.css CHANGED
@@ -40,7 +40,7 @@
40
  }
41
 
42
  #wp-insertpage-wrap.options-panel-visible {
43
- height: 525px;
44
  margin-top: -250px;
45
  }
46
 
@@ -298,7 +298,7 @@
298
  }
299
 
300
  #wp-insertpage-wrap.options-panel-visible {
301
- height: 530px;
302
  }
303
 
304
  #wp-insertpage-wrap .query-results {
@@ -332,7 +332,7 @@
332
  }
333
 
334
  #wp-insertpage-wrap.options-panel-visible {
335
- height: 550px;
336
  }
337
  }
338
 
40
  }
41
 
42
  #wp-insertpage-wrap.options-panel-visible {
43
+ height: 550px;
44
  margin-top: -250px;
45
  }
46
 
298
  }
299
 
300
  #wp-insertpage-wrap.options-panel-visible {
301
+ height: 555px;
302
  }
303
 
304
  #wp-insertpage-wrap .query-results {
332
  }
333
 
334
  #wp-insertpage-wrap.options-panel-visible {
335
+ height: 575px;
336
  }
337
  }
338
 
insert-pages.php CHANGED
@@ -7,7 +7,7 @@
7
  * Text Domain: insert-pages
8
  * Domain Path: /languages
9
  * License: GPL2
10
- * Version: 3.4.1
11
  *
12
  * @package insert-pages
13
  */
@@ -100,7 +100,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
100
  'wpinsertpages',
101
  plugins_url( '/js/wpinsertpages.js', __FILE__ ),
102
  array( 'wpdialogs' ),
103
- '20180201'
104
  );
105
  wp_localize_script(
106
  'wpinsertpages',
@@ -112,6 +112,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
112
  'noMatchesFound' => __( 'No matches found.', 'insert-pages' ),
113
  'l10n_print_after' => 'try{convertEntities(wpInsertPagesL10n);}catch(e){};',
114
  'format' => $options['wpip_format'],
 
115
  )
116
  );
117
 
@@ -120,7 +121,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
120
  'wpinsertpagescss',
121
  plugins_url( '/css/wpinsertpages.css', __FILE__ ),
122
  array( 'wp-jquery-ui-dialog' ),
123
- '20151230'
124
  );
125
 
126
  /**
@@ -160,6 +161,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
160
  'display' => 'all',
161
  'class' => '',
162
  'inline' => false,
 
163
  'querystring' => '',
164
  ), $atts, 'insert' );
165
 
@@ -168,10 +170,13 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
168
  return $content;
169
  }
170
 
171
- // Trying to embed same page in itself.
172
  if (
173
  ! is_null( $post ) && property_exists( $post, 'ID' ) &&
174
- ( intval( $attributes['page'] ) === $post->ID || $attributes['page'] === $post->post_name )
 
 
 
175
  ) {
176
  return $content;
177
  }
@@ -191,6 +196,8 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
191
  $attributes['inline'] = apply_filters( 'insert_pages_use_inline_wrapper', $attributes['inline'] );
192
  $attributes['wrapper_tag'] = $attributes['inline'] ? 'span' : 'div';
193
 
 
 
194
  /**
195
  * Filter the querystring values applied to every inserted page. Useful
196
  * for admins who want to provide the same querystring value to all
@@ -271,7 +278,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
271
  if ( is_null( $inserted_page ) ) {
272
  global $wpdb;
273
  $page = $wpdb->get_var( $wpdb->prepare(
274
- "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_status = 'publish' LIMIT 1", $attributes['page']
275
  ) );
276
  if ( $page ) {
277
  $inserted_page = get_post( $page );
@@ -283,6 +290,12 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
283
  $inserted_page = get_post( intval( $attributes['page'] ) );
284
  }
285
 
 
 
 
 
 
 
286
  // Set any querystring params included in the shortcode.
287
  parse_str( $attributes['querystring'], $querystring );
288
  $original_get = $_GET;
@@ -543,11 +556,13 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
543
  $args = array(
544
  'p' => intval( $attributes['page'] ),
545
  'post_type' => get_post_types(),
 
546
  );
547
  } else {
548
  $args = array(
549
  'name' => esc_attr( $attributes['page'] ),
550
  'post_type' => get_post_types(),
 
551
  );
552
  }
553
  $posts = query_posts( $args );
@@ -748,6 +763,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
748
  * display: Content to display from inserted page.
749
  * class: Extra classes to add to inserted page wrapper element.
750
  * inline: Boolean indicating wrapper element should be a span.
 
751
  * querystring: Extra querystring values provided to the custom template.
752
  * should_apply_nesting_check: Whether to disable nested inserted pages.
753
  * should_apply_the_content_filter: Whether to apply the_content filter to post contents and excerpts.
@@ -953,6 +969,11 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
953
  <?php esc_html_e( 'Querystring', 'insert-pages' ); ?>
954
  <input id="insertpage-extra-querystring" type="text" autocomplete="off" />
955
  </label>
 
 
 
 
 
956
  </div>
957
  </div>
958
  </div>
@@ -1037,7 +1058,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1037
  'suppress_filters' => true,
1038
  'update_post_term_cache' => false,
1039
  'update_post_meta_cache' => false,
1040
- 'post_status' => 'publish',
1041
  'order' => 'DESC',
1042
  'orderby' => 'post_date',
1043
  'posts_per_page' => 20,
@@ -1085,6 +1106,7 @@ if ( ! class_exists( 'InsertPagesPlugin' ) ) {
1085
  'slug' => $post->post_name,
1086
  'path' => get_page_uri( $post ),
1087
  'info' => $info,
 
1088
  );
1089
  }
1090
  return $results;
7
  * Text Domain: insert-pages
8
  * Domain Path: /languages
9
  * License: GPL2
10
+ * Version: 3.4.2
11
  *
12
  * @package insert-pages
13
  */
100
  'wpinsertpages',
101
  plugins_url( '/js/wpinsertpages.js', __FILE__ ),
102
  array( 'wpdialogs' ),
103
+ '20180702'
104
  );
105
  wp_localize_script(
106
  'wpinsertpages',
112
  'noMatchesFound' => __( 'No matches found.', 'insert-pages' ),
113
  'l10n_print_after' => 'try{convertEntities(wpInsertPagesL10n);}catch(e){};',
114
  'format' => $options['wpip_format'],
115
+ 'private' => __( 'Private' ),
116
  )
117
  );
118
 
121
  'wpinsertpagescss',
122
  plugins_url( '/css/wpinsertpages.css', __FILE__ ),
123
  array( 'wp-jquery-ui-dialog' ),
124
+ '20180702'
125
  );
126
 
127
  /**
161
  'display' => 'all',
162
  'class' => '',
163
  'inline' => false,
164
+ 'public' => false,
165
  'querystring' => '',
166
  ), $atts, 'insert' );
167
 
170
  return $content;
171
  }
172
 
173
+ // Short circuit if trying to embed same page in itself.
174
  if (
175
  ! is_null( $post ) && property_exists( $post, 'ID' ) &&
176
+ (
177
+ ( intval( $attributes['page'] ) > 0 && intval( $attributes['page'] ) === $post->ID ) ||
178
+ $attributes['page'] === $post->post_name
179
+ )
180
  ) {
181
  return $content;
182
  }
196
  $attributes['inline'] = apply_filters( 'insert_pages_use_inline_wrapper', $attributes['inline'] );
197
  $attributes['wrapper_tag'] = $attributes['inline'] ? 'span' : 'div';
198
 
199
+ $attributes['public'] = ( false !== $attributes['public'] && 'false' !== $attributes['public'] ) || array_search( 'public', $atts, true ) === 0 || is_user_logged_in();
200
+
201
  /**
202
  * Filter the querystring values applied to every inserted page. Useful
203
  * for admins who want to provide the same querystring value to all
278
  if ( is_null( $inserted_page ) ) {
279
  global $wpdb;
280
  $page = $wpdb->get_var( $wpdb->prepare(
281
+ "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND (post_status = 'publish' OR post_status = 'private') LIMIT 1", $attributes['page']
282
  ) );
283
  if ( $page ) {
284
  $inserted_page = get_post( $page );
290
  $inserted_page = get_post( intval( $attributes['page'] ) );
291
  }
292
 
293
+ // If inserted page's status is private, don't show to anonymous users
294
+ // unless 'public' option is set.
295
+ if ( 'private' === $inserted_page->post_status && ! $attributes['public'] ) {
296
+ $inserted_page = null;
297
+ }
298
+
299
  // Set any querystring params included in the shortcode.
300
  parse_str( $attributes['querystring'], $querystring );
301
  $original_get = $_GET;
556
  $args = array(
557
  'p' => intval( $attributes['page'] ),
558
  'post_type' => get_post_types(),
559
+ 'post_status' => $attributes['public'] ? array( 'publish', 'private' ) : array( 'publish' ),
560
  );
561
  } else {
562
  $args = array(
563
  'name' => esc_attr( $attributes['page'] ),
564
  'post_type' => get_post_types(),
565
+ 'post_status' => $attributes['public'] ? array( 'publish', 'private' ) : array( 'publish' ),
566
  );
567
  }
568
  $posts = query_posts( $args );
763
  * display: Content to display from inserted page.
764
  * class: Extra classes to add to inserted page wrapper element.
765
  * inline: Boolean indicating wrapper element should be a span.
766
+ * public: Boolean indicating anonymous users can see private inserted pages.
767
  * querystring: Extra querystring values provided to the custom template.
768
  * should_apply_nesting_check: Whether to disable nested inserted pages.
769
  * should_apply_the_content_filter: Whether to apply the_content filter to post contents and excerpts.
969
  <?php esc_html_e( 'Querystring', 'insert-pages' ); ?>
970
  <input id="insertpage-extra-querystring" type="text" autocomplete="off" />
971
  </label>
972
+ <br>
973
+ <label for="insertpage-extra-public">
974
+ <input id="insertpage-extra-public" type="checkbox" />
975
+ <?php esc_html_e( 'Anonymous users can see this inserted even if its status is private', 'insert-pages' ); ?>
976
+ </label>
977
  </div>
978
  </div>
979
  </div>
1058
  'suppress_filters' => true,
1059
  'update_post_term_cache' => false,
1060
  'update_post_meta_cache' => false,
1061
+ 'post_status' => array( 'publish', 'private' ),
1062
  'order' => 'DESC',
1063
  'orderby' => 'post_date',
1064
  'posts_per_page' => 20,
1106
  'slug' => $post->post_name,
1107
  'path' => get_page_uri( $post ),
1108
  'info' => $info,
1109
+ 'status' => get_post_status( $post ),
1110
  );
1111
  }
1112
  return $results;
js/wpinsertpages.js CHANGED
@@ -25,9 +25,10 @@ var wpInsertPages;
25
  inputs.parentPageID = $( '#insertpage-parent-page-id' );
26
  // Format field (title, link, content, all, choose a custom template ->)
27
  inputs.format = $( '#insertpage-format-select' );
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' );
@@ -242,7 +243,7 @@ var wpInsertPages;
242
  }
243
 
244
  // Update extra inline (i.e., use span instead of div for wrapper).
245
- regexp = /inline/;
246
  matches = regexp.exec( shortcode );
247
  if ( matches && matches.length > 0 ) {
248
  inputs.extraInline.attr( 'checked', true );
@@ -250,6 +251,15 @@ var wpInsertPages;
250
  inputs.extraInline.attr( 'checked', false );
251
  }
252
 
 
 
 
 
 
 
 
 
 
253
  // Update extra querystring.
254
  regexp = /querystring=['"]([^['"]*)['"]/;
255
  matches = regexp.exec( shortcode );
@@ -308,6 +318,7 @@ var wpInsertPages;
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
  },
@@ -340,6 +351,7 @@ var wpInsertPages;
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
  + "'" : ""
@@ -582,7 +594,9 @@ var wpInsertPages;
582
  list += '<input type="hidden" class="item-id" value="' + this.ID + '" />';
583
  list += '<span class="item-title">';
584
  list += this.title ? this.title : wpInsertPagesL10n.noTitle;
585
- list += '</span><span class="item-info">' + this.info + '</span></li>';
 
 
586
  alt = ! alt;
587
  });
588
  }
25
  inputs.parentPageID = $( '#insertpage-parent-page-id' );
26
  // Format field (title, link, content, all, choose a custom template ->)
27
  inputs.format = $( '#insertpage-format-select' );
28
+ // Extra fields (wrapper classes, inline checkbox, "visible to all" checkbox)
29
  inputs.extraClasses = $( '#insertpage-extra-classes' );
30
  inputs.extraInline = $( '#insertpage-extra-inline' );
31
+ inputs.extraPublic = $( '#insertpage-extra-public' );
32
  inputs.extraQuerystring = $( '#insertpage-extra-querystring' );
33
  // Custom template select field
34
  inputs.template = $( '#insertpage-template-select' );
243
  }
244
 
245
  // Update extra inline (i.e., use span instead of div for wrapper).
246
+ regexp = /[\s]inline[\s\]]/;
247
  matches = regexp.exec( shortcode );
248
  if ( matches && matches.length > 0 ) {
249
  inputs.extraInline.attr( 'checked', true );
251
  inputs.extraInline.attr( 'checked', false );
252
  }
253
 
254
+ // If this is a private page, reveal the checkbox "Visible to everyone?"
255
+ regexp = /[\s]public[\s\]]/;
256
+ matches = regexp.exec( shortcode );
257
+ if ( matches && matches.length > 0 ) {
258
+ inputs.extraPublic.attr( 'checked', true );
259
+ } else {
260
+ inputs.extraPublic.attr( 'checked', false );
261
+ }
262
+
263
  // Update extra querystring.
264
  regexp = /querystring=['"]([^['"]*)['"]/;
265
  matches = regexp.exec( shortcode );
318
  display: inputs.format.val()=='template' ? inputs.template.val() : inputs.format.val(),
319
  class: inputs.extraClasses.val(),
320
  inline: inputs.extraInline.is( ':checked' ),
321
+ public: inputs.extraPublic.is( ':checked' ),
322
  querystring: inputs.extraQuerystring.val(),
323
  };
324
  },
351
  "display='" + attrs.display + "'" +
352
  ( attrs['class'].length > 0 ? " class='" + attrs['class'] + "'" : "" ) +
353
  ( attrs.inline ? " inline" : "" ) +
354
+ ( attrs.public ? " public" : "" ) +
355
  ( attrs.querystring ? " querystring='" +
356
  attrs['querystring'].replace( /&/g, '&amp;' ).replace( /\[/g, '{' ).replace( /\]/g, '}' )
357
  + "'" : ""
594
  list += '<input type="hidden" class="item-id" value="' + this.ID + '" />';
595
  list += '<span class="item-title">';
596
  list += this.title ? this.title : wpInsertPagesL10n.noTitle;
597
+ list += '</span><span class="item-info">' + this.info;
598
+ list += this.status === 'private' ? ' (' + wpInsertPagesL10n.private + ')' : '';
599
+ list += '</span></li>';
600
  alt = ! alt;
601
  });
602
  }
readme.txt CHANGED
@@ -86,6 +86,11 @@ Just one! The plugin prevents you from embedding a page in itself, but you can t
86
 
87
  == Changelog ==
88
 
 
 
 
 
 
89
  = 3.4.1 =
90
  * Fix for Elementor rendering in legacy mode.
91
  * Fix for Post Thumbnail display in legacy mode.
86
 
87
  == Changelog ==
88
 
89
+ = 3.4.2 =
90
+ * Add 'public' shortcode param that lets private inserted pages be visible to anonymous users. Props @ahtcx for the suggestion.
91
+ * Fix for inserted pages shown on BuddyPress profiles. Props @IdleWanderer for the report!
92
+ * Fix for querystring option missing from widget settings.
93
+
94
  = 3.4.1 =
95
  * Fix for Elementor rendering in legacy mode.
96
  * Fix for Post Thumbnail display in legacy mode.
widget.php CHANGED
@@ -64,6 +64,12 @@ class InsertPagesWidget extends WP_Widget {
64
  if ( array_key_exists( 'inline', $instance ) ) {
65
  $atts['inline'] = '1' === $instance['inline'];
66
  }
 
 
 
 
 
 
67
 
68
  // Render the inserted page using the plugin's shortcode handler.
69
  $content = $insert_pages_plugin->insert_pages_handle_shortcode_insert( $atts );
@@ -87,6 +93,8 @@ class InsertPagesWidget extends WP_Widget {
87
  'template' => '',
88
  'class' => '',
89
  'inline' => '',
 
 
90
  )); ?>
91
  <p>
92
  <label for="<?php echo esc_attr( $this->get_field_id( 'page' ) ); ?>"><?php esc_html_e( 'Page/Post ID or Slug', 'insert-pages' ); ?>:</label>
@@ -119,6 +127,14 @@ class InsertPagesWidget extends WP_Widget {
119
  <input class="checkbox" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'inline' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'inline' ) ); ?>" value="1" <?php checked( $instance['inline'], '1' ); ?> />
120
  <label for="<?php echo esc_attr( $this->get_field_id( 'inline' ) ); ?>"><?php esc_html_e( 'Inline?', 'insert-pages' ); ?></label>
121
  </p>
 
 
 
 
 
 
 
 
122
  <?php
123
  }
124
 
@@ -136,6 +152,8 @@ class InsertPagesWidget extends WP_Widget {
136
  $instance['template'] = array_key_exists( 'template', $new_instance ) ? strip_tags( $new_instance['template'] ) : '';
137
  $instance['class'] = array_key_exists( 'class', $new_instance ) ? strip_tags( $new_instance['class'] ) : '';
138
  $instance['inline'] = array_key_exists( 'inline', $new_instance ) ? strip_tags( $new_instance['inline'] ) : '';
 
 
139
 
140
  return $instance;
141
  }
64
  if ( array_key_exists( 'inline', $instance ) ) {
65
  $atts['inline'] = '1' === $instance['inline'];
66
  }
67
+ if ( array_key_exists( 'querystring', $instance ) ) {
68
+ $atts['querystring'] = $instance['querystring'];
69
+ }
70
+ if ( array_key_exists( 'public', $instance ) ) {
71
+ $atts['public'] = '1' === $instance['public'];
72
+ }
73
 
74
  // Render the inserted page using the plugin's shortcode handler.
75
  $content = $insert_pages_plugin->insert_pages_handle_shortcode_insert( $atts );
93
  'template' => '',
94
  'class' => '',
95
  'inline' => '',
96
+ 'querystring' => '',
97
+ 'public' => '',
98
  )); ?>
99
  <p>
100
  <label for="<?php echo esc_attr( $this->get_field_id( 'page' ) ); ?>"><?php esc_html_e( 'Page/Post ID or Slug', 'insert-pages' ); ?>:</label>
127
  <input class="checkbox" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'inline' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'inline' ) ); ?>" value="1" <?php checked( $instance['inline'], '1' ); ?> />
128
  <label for="<?php echo esc_attr( $this->get_field_id( 'inline' ) ); ?>"><?php esc_html_e( 'Inline?', 'insert-pages' ); ?></label>
129
  </p>
130
+ <p>
131
+ <label for="<?php echo esc_attr( $this->get_field_id( 'querystring' ) ); ?>"><?php esc_html_e( 'Querystring', 'insert-pages' ); ?>:</label>
132
+ <input type="text" class="widefat" autocomplete="off" name="<?php echo esc_attr( $this->get_field_name( 'querystring' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'querystring' ) ); ?>" value="<?php echo esc_attr( $instance['querystring'] ); ?>" />
133
+ </p>
134
+ <p>
135
+ <input class="checkbox" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'public' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'public' ) ); ?>" value="1" <?php checked( $instance['public'], '1' ); ?> />
136
+ <label for="<?php echo esc_attr( $this->get_field_id( 'public' ) ); ?>"><?php esc_html_e( 'Anonymous users can see this inserted even if its status is private', 'insert-pages' ); ?></label>
137
+ </p>
138
  <?php
139
  }
140
 
152
  $instance['template'] = array_key_exists( 'template', $new_instance ) ? strip_tags( $new_instance['template'] ) : '';
153
  $instance['class'] = array_key_exists( 'class', $new_instance ) ? strip_tags( $new_instance['class'] ) : '';
154
  $instance['inline'] = array_key_exists( 'inline', $new_instance ) ? strip_tags( $new_instance['inline'] ) : '';
155
+ $instance['querystring'] = array_key_exists( 'querystring', $new_instance ) ? strip_tags( $new_instance['querystring'] ) : '';
156
+ $instance['public'] = array_key_exists( 'public', $new_instance ) ? strip_tags( $new_instance['public'] ) : '';
157
 
158
  return $instance;
159
  }