Insert Pages - Version 3.0.1

Version Description

  • Hotfix: Version 3 broke some plugin compatibility (most notably with Beaver Builder and Page Builder by SiteOrigin). This update should restore functionality.
  • Hotfix: Version 3 broke some page displays (e.g., content, all). This update should restore functionality.
Download this release

Release Info

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

Code changes from version 3.0 to 3.0.1

Files changed (3) hide show
  1. insert-pages.php +232 -107
  2. options.php +25 -2
  3. readme.txt +7 -3
insert-pages.php CHANGED
@@ -5,7 +5,7 @@ Plugin Name: Insert Pages
5
  Plugin URI: https://github.com/uhm-coe/insert-pages
6
  Description: Insert Pages lets you embed any WordPress content (e.g., pages, posts, custom post types) into other WordPress content using the Shortcode API.
7
  Author: Paul Ryan
8
- Version: 3.0
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
@@ -59,7 +59,7 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
59
  function insertPages_admin_init() {
60
  // Get options set in WordPress dashboard (Settings > Insert Pages).
61
  $options = get_option( 'wpip_settings' );
62
- if ( $options === FALSE ) {
63
  $options = wpip_set_defaults();
64
  }
65
 
@@ -127,7 +127,7 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
127
 
128
  // Get options set in WordPress dashboard (Settings > Insert Pages).
129
  $options = get_option( 'wpip_settings' );
130
- if ( $options === FALSE ) {
131
  $options = wpip_set_defaults();
132
  }
133
 
@@ -211,99 +211,123 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
211
  $post->ID = $old_post_id;
212
  }
213
 
214
- // Start output buffering so we can save the output to a string.
215
- ob_start();
216
-
217
- // Show either the title, link, content, everything, or everything via a custom template
218
- // Note: if the sharing_display filter exists, it means Jetpack is installed and Sharing is enabled;
219
- // This plugin conflicts with Sharing, because Sharing assumes the_content and the_excerpt filters
220
- // are only getting called once. The fix here is to disable processing of filters on the_content in
221
- // the inserted page. @see https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage
222
- switch ( $attributes['display'] ) {
223
-
224
- case "title":
225
- $title_tag = $attributes['inline'] ? 'span' : 'h1';
226
- echo "<$title_tag class='insert-page-title'>";
227
- get_the_title( $inserted_page->ID );
228
- echo "</$title_tag>";
229
- break;
230
-
231
- case "link":
232
- ?><a href="<?php echo esc_url( get_permalink( $inserted_page->ID ) ); ?>"><?php get_the_title( $inserted_page->ID ); ?></a><?php
233
- break;
234
-
235
- case "excerpt":
236
- ?><h1><a href="<?php echo esc_url( get_permalink( $inserted_page->ID ) ); ?>"><?php get_the_title( $inserted_page->ID ); ?></a></h1><?php
237
- $excerpt = get_post_field( 'post_excerpt', $inserted_page->ID );
238
- if ( $attributes['should_apply_the_content_filter'] ) {
239
- $excerpt = apply_filters( 'the_excerpt', $excerpt );
240
- }
241
- echo $excerpt;
242
- break;
243
 
244
- case "excerpt-only":
245
- $excerpt = get_post_field( 'post_excerpt', $inserted_page->ID );
246
- if ( $attributes['should_apply_the_content_filter'] ) {
247
- $excerpt = apply_filters( 'the_excerpt', $excerpt );
248
- }
249
- echo $excerpt;
250
- break;
251
 
252
- case "content":
253
- $content = get_post_field( 'post_content', $inserted_page->ID );
254
- if ( $attributes['should_apply_the_content_filter'] ) {
255
- $content = apply_filters( 'the_content', $content );
256
- }
257
- echo $content;
258
- break;
259
-
260
- case "all":
261
- // Title.
262
- $title_tag = $attributes['inline'] ? 'span' : 'h1';
263
- echo "<$title_tag class='insert-page-title'>";
264
- get_the_title( $inserted_page->ID );
265
- echo "</$title_tag>";
266
- // Content.
267
- $content = get_post_field( 'post_content', $inserted_page->ID );
268
- if ( $attributes['should_apply_the_content_filter'] ) {
269
- $content = apply_filters( 'the_content', $content );
270
- }
271
- echo $content;
272
- // Meta.
273
- // @ref https://core.trac.wordpress.org/browser/tags/4.4/src/wp-includes/post-template.php#L968
274
- if ( $keys = get_post_custom_keys( $inserted_page->ID ) ) {
275
- echo "<ul class='post-meta'>\n";
276
- foreach ( (array) $keys as $key ) {
277
- $keyt = trim( $key );
278
- if ( is_protected_meta( $keyt, 'post' ) ) {
279
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  }
281
- $values = array_map( 'trim', get_post_custom_values( $key ) );
282
- $value = implode( $values, ', ' );
283
-
284
- /**
285
- * Filter the HTML output of the li element in the post custom fields list.
286
- *
287
- * @since 2.2.0
288
- *
289
- * @param string $html The HTML output for the li element.
290
- * @param string $key Meta key.
291
- * @param string $value Meta value.
292
- */
293
- echo apply_filters( 'the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value );
294
  }
295
- echo "</ul>\n";
 
296
  }
297
- break;
298
-
299
- default: // display is either invalid, or contains a template file to use
300
- // Legacy/compatibility code: In order to use custom templates,
301
- // we use query_posts() to provide the template with the global
302
- // state it requires for the inserted page (in other words, all
303
- // template tags will work with respect to the inserted page
304
- // instead of the parent page / main loop). Note that this may
305
- // cause some compatibility issues with other plugins.
306
- // @ref https://codex.wordpress.org/Function_Reference/query_posts
307
  if ( is_numeric( $attributes['page'] ) ) {
308
  $args = array(
309
  'p' => intval( $attributes['page'] ),
@@ -315,24 +339,66 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
315
  'post_type' => get_post_types(),
316
  );
317
  }
318
- $inserted_page = query_posts( $args );
319
  if ( have_posts() ) {
320
- $template = locate_template( $attributes['display'] );
321
- if ( strlen( $template ) > 0 ) {
322
- include $template; // execute the template code
323
- } else { // Couldn't find template, so fall back to printing a link to the page.
 
 
 
 
 
 
 
 
 
 
 
 
324
  the_post();
325
  ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  }
327
- break;
 
 
328
  }
329
  wp_reset_query();
330
-
331
  }
332
 
333
- // Save output buffer contents.
334
- $content = ob_get_clean();
335
-
336
  /**
337
  * Filter the markup generated for the inserted page.
338
  *
@@ -369,6 +435,55 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
369
  return $plugins;
370
  }
371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
  /**
373
  * Modified from /wp-admin/includes/internal-linking.php, function wp_link_dialog()
374
  * Dialog for internal linking.
@@ -438,7 +553,7 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
438
  <select name="insertpage-format-select" id="insertpage-format-select">
439
  <option value='title'>Title</option>
440
  <option value='link'>Link</option>
441
- <option value='excerpt'>Excerpt</option>
442
  <option value='excerpt-only'>Excerpt only (no title)</option>
443
  <option value='content'>Content</option>
444
  <option value='all'>All (includes custom fields)</option>
@@ -611,11 +726,21 @@ if ( class_exists( 'InsertPagesPlugin' ) ) {
611
 
612
  // Actions and Filters handled by InsertPagesPlugin class
613
  if ( isset( $insertPages_plugin ) ) {
614
- // Actions
615
- add_action( 'init', array( $insertPages_plugin, 'insertPages_init' ), 1 ); // Register Shortcodes here
616
- add_action( 'admin_head', array( $insertPages_plugin, 'insertPages_admin_init' ), 1 ); // Add TinyMCE buttons here
617
- add_action( 'before_wp_tiny_mce', array( $insertPages_plugin, 'insertPages_wp_tinymce_dialog' ), 1 ); // Preload TinyMCE popup
618
- add_action( 'wp_ajax_insertpage', array( $insertPages_plugin, 'insertPages_insert_page_callback' ) ); // Populate page search in TinyMCE button popup in this ajax call
 
 
619
  add_action( 'admin_print_footer_scripts', array( $insertPages_plugin, 'insertPages_add_quicktags' ) );
 
 
 
 
 
 
 
 
620
  add_filter( 'insert_pages_wrap_content', array( $insertPages_plugin, 'insertPages_wrap_content' ), 10, 3 );
621
  }
5
  Plugin URI: https://github.com/uhm-coe/insert-pages
6
  Description: Insert Pages lets you embed any WordPress content (e.g., pages, posts, custom post types) into other WordPress content using the Shortcode API.
7
  Author: Paul Ryan
8
+ Version: 3.0.1
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
59
  function insertPages_admin_init() {
60
  // Get options set in WordPress dashboard (Settings > Insert Pages).
61
  $options = get_option( 'wpip_settings' );
62
+ if ( $options === FALSE || ! is_array( $options ) || ! array_key_exists( 'wpip_format', $options ) || ! array_key_exists( 'wpip_wrapper', $options ) || ! array_key_exists( 'wpip_insert_method', $options ) ) {
63
  $options = wpip_set_defaults();
64
  }
65
 
127
 
128
  // Get options set in WordPress dashboard (Settings > Insert Pages).
129
  $options = get_option( 'wpip_settings' );
130
+ if ( $options === FALSE || ! is_array( $options ) || ! array_key_exists( 'wpip_format', $options ) || ! array_key_exists( 'wpip_wrapper', $options ) || ! array_key_exists( 'wpip_insert_method', $options ) ) {
131
  $options = wpip_set_defaults();
132
  }
133
 
211
  $post->ID = $old_post_id;
212
  }
213
 
214
+ // Use "Normal" insert method (get_post()).
215
+ if ( $options['wpip_insert_method'] !== 'legacy' ) {
216
+ // Start output buffering so we can save the output to a string.
217
+ ob_start();
218
+
219
+ // Show either the title, link, content, everything, or everything via a custom template
220
+ // Note: if the sharing_display filter exists, it means Jetpack is installed and Sharing is enabled;
221
+ // This plugin conflicts with Sharing, because Sharing assumes the_content and the_excerpt filters
222
+ // are only getting called once. The fix here is to disable processing of filters on the_content in
223
+ // the inserted page. @see https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage
224
+ switch ( $attributes['display'] ) {
225
+
226
+ case "title":
227
+ $title_tag = $attributes['inline'] ? 'span' : 'h1';
228
+ echo "<$title_tag class='insert-page-title'>";
229
+ echo get_the_title( $inserted_page->ID );
230
+ echo "</$title_tag>";
231
+ break;
 
 
 
 
 
 
 
 
 
 
 
232
 
233
+ case "link":
234
+ ?><a href="<?php echo esc_url( get_permalink( $inserted_page->ID ) ); ?>"><?php echo get_the_title( $inserted_page->ID ); ?></a><?php
235
+ break;
 
 
 
 
236
 
237
+ case "excerpt":
238
+ ?><h1><a href="<?php echo esc_url( get_permalink( $inserted_page->ID ) ); ?>"><?php echo get_the_title( $inserted_page->ID ); ?></a></h1><?php
239
+ echo $this->insertPages_trim_excerpt( get_post_field( 'post_excerpt', $inserted_page->ID ), $inserted_page->ID, $attributes['should_apply_the_content_filter'] );
240
+ break;
241
+
242
+ case "excerpt-only":
243
+ echo $this->insertPages_trim_excerpt( get_post_field( 'post_excerpt', $inserted_page->ID ), $inserted_page->ID, $attributes['should_apply_the_content_filter'] );
244
+ break;
245
+
246
+ case "content":
247
+ $content = get_post_field( 'post_content', $inserted_page->ID );
248
+ if ( $attributes['should_apply_the_content_filter'] ) {
249
+ $content = apply_filters( 'the_content', $content );
250
+ }
251
+ echo $content;
252
+ break;
253
+
254
+ case "all":
255
+ // Title.
256
+ $title_tag = $attributes['inline'] ? 'span' : 'h1';
257
+ echo "<$title_tag class='insert-page-title'>";
258
+ echo get_the_title( $inserted_page->ID );
259
+ echo "</$title_tag>";
260
+ // Content.
261
+ $content = get_post_field( 'post_content', $inserted_page->ID );
262
+ if ( $attributes['should_apply_the_content_filter'] ) {
263
+ $content = apply_filters( 'the_content', $content );
264
+ }
265
+ echo $content;
266
+ // Meta.
267
+ // @ref https://core.trac.wordpress.org/browser/tags/4.4/src/wp-includes/post-template.php#L968
268
+ if ( $keys = get_post_custom_keys( $inserted_page->ID ) ) {
269
+ echo "<ul class='post-meta'>\n";
270
+ foreach ( (array) $keys as $key ) {
271
+ $keyt = trim( $key );
272
+ if ( is_protected_meta( $keyt, 'post' ) ) {
273
+ continue;
274
+ }
275
+ $values = array_map( 'trim', get_post_custom_values( $key ) );
276
+ $value = implode( $values, ', ' );
277
+
278
+ /**
279
+ * Filter the HTML output of the li element in the post custom fields list.
280
+ *
281
+ * @since 2.2.0
282
+ *
283
+ * @param string $html The HTML output for the li element.
284
+ * @param string $key Meta key.
285
+ * @param string $value Meta value.
286
+ */
287
+ echo apply_filters( 'the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value );
288
+ }
289
+ echo "</ul>\n";
290
+ }
291
+ break;
292
+
293
+ default: // display is either invalid, or contains a template file to use
294
+ // Legacy/compatibility code: In order to use custom templates,
295
+ // we use query_posts() to provide the template with the global
296
+ // state it requires for the inserted page (in other words, all
297
+ // template tags will work with respect to the inserted page
298
+ // instead of the parent page / main loop). Note that this may
299
+ // cause some compatibility issues with other plugins.
300
+ // @ref https://codex.wordpress.org/Function_Reference/query_posts
301
+ if ( is_numeric( $attributes['page'] ) ) {
302
+ $args = array(
303
+ 'p' => intval( $attributes['page'] ),
304
+ 'post_type' => get_post_types(),
305
+ );
306
+ } else {
307
+ $args = array(
308
+ 'name' => esc_attr( $attributes['page'] ),
309
+ 'post_type' => get_post_types(),
310
+ );
311
+ }
312
+ $inserted_page = query_posts( $args );
313
+ if ( have_posts() ) {
314
+ $template = locate_template( $attributes['display'] );
315
+ if ( strlen( $template ) > 0 ) {
316
+ include $template; // execute the template code
317
+ } else { // Couldn't find template, so fall back to printing a link to the page.
318
+ the_post();
319
+ ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
320
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  }
322
+ wp_reset_query();
323
+
324
  }
325
+
326
+ // Save output buffer contents.
327
+ $content = ob_get_clean();
328
+
329
+ // Use "Legacy" insert method (query_posts()).
330
+ } else {
 
 
 
 
331
  if ( is_numeric( $attributes['page'] ) ) {
332
  $args = array(
333
  'p' => intval( $attributes['page'] ),
339
  'post_type' => get_post_types(),
340
  );
341
  }
342
+ $posts = query_posts( $args );
343
  if ( have_posts() ) {
344
+ // Start output buffering so we can save the output to string
345
+ ob_start();
346
+ // Show either the title, link, content, everything, or everything via a custom template
347
+ // Note: if the sharing_display filter exists, it means Jetpack is installed and Sharing is enabled;
348
+ // This plugin conflicts with Sharing, because Sharing assumes the_content and the_excerpt filters
349
+ // are only getting called once. The fix here is to disable processing of filters on the_content in
350
+ // the inserted page. @see https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage
351
+ switch ( $attributes['display'] ) {
352
+ case "title":
353
+ the_post();
354
+ $title_tag = $attributes['inline'] ? 'span' : 'h1';
355
+ echo "<$title_tag class='insert-page-title'>";
356
+ the_title();
357
+ echo "</$title_tag>";
358
+ break;
359
+ case "link":
360
  the_post();
361
  ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
362
+ break;
363
+ case "excerpt":
364
+ the_post();
365
+ ?><h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1><?php
366
+ if ( $attributes['should_apply_the_content_filter'] ) the_excerpt(); else echo get_the_excerpt();
367
+ break;
368
+ case "excerpt-only":
369
+ the_post();
370
+ if ( $attributes['should_apply_the_content_filter'] ) the_excerpt(); else echo get_the_excerpt();
371
+ break;
372
+ case "content":
373
+ the_post();
374
+ if ( $attributes['should_apply_the_content_filter'] ) the_content(); else echo get_the_content();
375
+ break;
376
+ case "all":
377
+ the_post();
378
+ $title_tag = $attributes['inline'] ? 'span' : 'h1';
379
+ echo "<$title_tag class='insert-page-title'>";
380
+ the_title();
381
+ echo "</$title_tag>";
382
+ if ( $attributes['should_apply_the_content_filter'] ) the_content(); else echo get_the_content();
383
+ the_meta();
384
+ break;
385
+ default: // display is either invalid, or contains a template file to use
386
+ $template = locate_template( $attributes['display'] );
387
+ if ( strlen( $template ) > 0 ) {
388
+ include $template; // execute the template code
389
+ } else { // Couldn't find template, so fall back to printing a link to the page.
390
+ the_post();
391
+ ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
392
+ }
393
+ break;
394
  }
395
+ // Save output buffer contents.
396
+ $content = ob_get_clean();
397
+
398
  }
399
  wp_reset_query();
 
400
  }
401
 
 
 
 
402
  /**
403
  * Filter the markup generated for the inserted page.
404
  *
435
  return $plugins;
436
  }
437
 
438
+ // Helper function to generate an excerpt (outside of the Loop) for a given ID.
439
+ // @ref wp_trim_excerpt()
440
+ function insertPages_trim_excerpt( $text = '', $post_id = 0, $apply_the_content_filter = true ) {
441
+ $post_id = intval( $post_id );
442
+ if ( $post_id < 1 ) {
443
+ return '';
444
+ }
445
+
446
+ $raw_excerpt = $text;
447
+ if ( '' == $text ) {
448
+ $text = get_post_field( 'post_content', $post_id );
449
+
450
+ $text = strip_shortcodes( $text );
451
+
452
+ /** This filter is documented in wp-includes/post-template.php */
453
+ if ( $apply_the_content_filter ) {
454
+ $text = apply_filters( 'the_content', $text );
455
+ }
456
+ $text = str_replace( ']]>', ']]&gt;', $text );
457
+
458
+ /**
459
+ * Filter the number of words in an excerpt.
460
+ *
461
+ * @since 2.7.0
462
+ *
463
+ * @param int $number The number of words. Default 55.
464
+ */
465
+ $excerpt_length = apply_filters( 'excerpt_length', 55 );
466
+ /**
467
+ * Filter the string in the "more" link displayed after a trimmed excerpt.
468
+ *
469
+ * @since 2.9.0
470
+ *
471
+ * @param string $more_string The string shown within the more link.
472
+ */
473
+ $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
474
+ $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
475
+ }
476
+ /**
477
+ * Filter the trimmed excerpt string.
478
+ *
479
+ * @since 2.8.0
480
+ *
481
+ * @param string $text The trimmed text.
482
+ * @param string $raw_excerpt The text prior to trimming.
483
+ */
484
+ return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
485
+ }
486
+
487
  /**
488
  * Modified from /wp-admin/includes/internal-linking.php, function wp_link_dialog()
489
  * Dialog for internal linking.
553
  <select name="insertpage-format-select" id="insertpage-format-select">
554
  <option value='title'>Title</option>
555
  <option value='link'>Link</option>
556
+ <option value='excerpt'>Excerpt with title</option>
557
  <option value='excerpt-only'>Excerpt only (no title)</option>
558
  <option value='content'>Content</option>
559
  <option value='all'>All (includes custom fields)</option>
726
 
727
  // Actions and Filters handled by InsertPagesPlugin class
728
  if ( isset( $insertPages_plugin ) ) {
729
+ // Register shortcode [insert ...].
730
+ add_action( 'init', array( $insertPages_plugin, 'insertPages_init' ), 1 );
731
+
732
+ // Add TinyMCE button for shortcode.
733
+ add_action( 'admin_head', array( $insertPages_plugin, 'insertPages_admin_init' ), 1 );
734
+
735
+ // Add quicktags button for shortcode.
736
  add_action( 'admin_print_footer_scripts', array( $insertPages_plugin, 'insertPages_add_quicktags' ) );
737
+
738
+ // Preload TinyMCE popup.
739
+ add_action( 'before_wp_tiny_mce', array( $insertPages_plugin, 'insertPages_wp_tinymce_dialog' ), 1 );
740
+
741
+ // Ajax: Populate page search in TinyMCE button popup.
742
+ add_action( 'wp_ajax_insertpage', array( $insertPages_plugin, 'insertPages_insert_page_callback' ) );
743
+
744
+ // Use internal filter to wrap inserted content in a div or span.
745
  add_filter( 'insert_pages_wrap_content', array( $insertPages_plugin, 'insertPages_wrap_content' ), 10, 3 );
746
  }
options.php CHANGED
@@ -28,6 +28,13 @@ function wpip_settings_init() {
28
  'wpipSettings',
29
  'wpip_section'
30
  );
 
 
 
 
 
 
 
31
  }
32
  add_action( 'admin_init', 'wpip_settings_init' );
33
 
@@ -46,6 +53,10 @@ function wpip_set_defaults() {
46
  $options['wpip_wrapper'] = 'block';
47
  }
48
 
 
 
 
 
49
  update_option( 'wpip_settings', $options );
50
 
51
  return $options;
@@ -73,7 +84,7 @@ function wpip_options_page() {
73
 
74
  function wpip_format_render() {
75
  $options = get_option( 'wpip_settings' );
76
- if ( $options === FALSE ) {
77
  $options = wpip_set_defaults();
78
  }
79
  ?>
@@ -86,7 +97,7 @@ function wpip_format_render() {
86
 
87
  function wpip_wrapper_render() {
88
  $options = get_option( 'wpip_settings' );
89
- if ( $options === FALSE ) {
90
  $options = wpip_set_defaults();
91
  }
92
  ?>
@@ -95,3 +106,15 @@ function wpip_wrapper_render() {
95
  <small><em>If you want to embed pages inline (for example, you can insert a link to a page in the flow of a normal paragraph), you should use inline tags. Note that the HTML spec does not allow block level elements within inline elements, so the inline wrapper has limited use.</em></small>
96
  <?php
97
  }
 
 
 
 
 
 
 
 
 
 
 
 
28
  'wpipSettings',
29
  'wpip_section'
30
  );
31
+ add_settings_field(
32
+ 'wpip_insert_method',
33
+ __( 'Insert method', 'wordpress' ),
34
+ 'wpip_insert_method_render',
35
+ 'wpipSettings',
36
+ 'wpip_section'
37
+ );
38
  }
39
  add_action( 'admin_init', 'wpip_settings_init' );
40
 
53
  $options['wpip_wrapper'] = 'block';
54
  }
55
 
56
+ if ( ! array_key_exists( 'wpip_insert_method', $options ) ) {
57
+ $options['wpip_insert_method'] = 'legacy';
58
+ }
59
+
60
  update_option( 'wpip_settings', $options );
61
 
62
  return $options;
84
 
85
  function wpip_format_render() {
86
  $options = get_option( 'wpip_settings' );
87
+ if ( $options === FALSE || ! is_array( $options ) || ! array_key_exists( 'wpip_format', $options ) ) {
88
  $options = wpip_set_defaults();
89
  }
90
  ?>
97
 
98
  function wpip_wrapper_render() {
99
  $options = get_option( 'wpip_settings' );
100
+ if ( $options === FALSE || ! is_array( $options ) || ! array_key_exists( 'wpip_wrapper', $options ) ) {
101
  $options = wpip_set_defaults();
102
  }
103
  ?>
106
  <small><em>If you want to embed pages inline (for example, you can insert a link to a page in the flow of a normal paragraph), you should use inline tags. Note that the HTML spec does not allow block level elements within inline elements, so the inline wrapper has limited use.</em></small>
107
  <?php
108
  }
109
+
110
+ function wpip_insert_method_render() {
111
+ $options = get_option( 'wpip_settings' );
112
+ if ( $options === FALSE || ! is_array( $options ) || ! array_key_exists( 'wpip_insert_method', $options ) ) {
113
+ $options = wpip_set_defaults();
114
+ }
115
+ ?>
116
+ <input type='radio' name='wpip_settings[wpip_insert_method]' <?php checked( $options['wpip_insert_method'], 'legacy' ); ?> id="wpip_insert_method_legacy" value='legacy'><label for="wpip_insert_method_legacy">Use legacy method (compatible with <a href="https://wordpress.org/plugins/beaver-builder-lite-version/" target="_blank">Beaver Builder</a> and <a href="https://wordpress.org/plugins/siteorigin-panels/" target="_blank">Page Builder by SiteOrigin</a>, but less efficient). </label><br />
117
+ <input type='radio' name='wpip_settings[wpip_insert_method]' <?php checked( $options['wpip_insert_method'], 'normal' ); ?> id="wpip_insert_method_normal" value='normal'><label for="wpip_insert_method_normal">Use normal method (more compatible with other plugins, and more efficient).</label><br />
118
+ <small><em>The legacy method uses <a href="https://codex.wordpress.org/Function_Reference/query_posts" target="_blank">query_posts()</a>, which the Codex cautions against using. However, to recreate the exact state that many page builder plugins are expecting, the Main Loop has to be replaced with the inserted page while it is being rendered. The normal method, on the other hand, just uses <a href="https://developer.wordpress.org/reference/functions/get_post/" target="_blank">get_post()</a>.</em></small>
119
+ <?php
120
+ }
readme.txt CHANGED
@@ -17,7 +17,7 @@ The real power of Insert Pages comes when you start creating custom post types,
17
 
18
  Here are two quick example use cases:
19
 
20
- ### Novice Use Case
21
  Say you teach a course and you're constantly referring to an assignment due date in your course website. The next semester the due date changes, and you have to go change all of the locations you referred to it. Instead, you'd rather just change the date once! With Insert Pages, you can do the following:
22
 
23
  1. Create a custom post type called **Due Date**.
@@ -25,7 +25,7 @@ Say you teach a course and you're constantly referring to an assignment due date
25
  1. Edit all the pages where the due date occurs and use the *Insert Pages* toolbar button to insert a reference to the *Due Date* you just created. Be sure to set the *Display* to **Content** so *Fri Nov 22, 2013* shows wherever you insert it. The shortcode you just created should look something like this: `[insert page='assignment-1-due-date' display='content']`
26
  1. That's it! Now, when you want to change the due date, just edit the *Assignment 1 Due Date* custom post you created, and it will automatically be updated on all the pages you inserted it on.
27
 
28
- ### Expert Use Case
29
  Say your site has a lot of video content, and you want to include video transcripts and video lengths along with the videos wherever you show them. You could just paste the transcripts into the page content under the video, but then you'd have to do this on every page the video showed on. (It's also just a bad idea, architecturally!) With Insert Pages, you can use a custom post type and create a custom theme template to display your videos+transcripts+lengths just the way you want!
30
 
31
  1. Create a custom post type called **Video**.
@@ -86,8 +86,12 @@ Just one! The plugin prevents you from embedding a page in itself, but you can t
86
 
87
  == Changelog ==
88
 
 
 
 
 
89
  = 3.0 =
90
- * Hotfix: 2.9.1 broke extra classes added to the inserted page wrapper.
91
  * Feature: Expose extra classes and inline status in tinymce dialog.
92
  * One more API change to insert_pages_wrap_content_filter (2nd parameter is a WP_Post now instead of an array of WP_Posts, since we only ever insert one page).
93
  Example 1:
17
 
18
  Here are two quick example use cases:
19
 
20
+ ### Normal Use
21
  Say you teach a course and you're constantly referring to an assignment due date in your course website. The next semester the due date changes, and you have to go change all of the locations you referred to it. Instead, you'd rather just change the date once! With Insert Pages, you can do the following:
22
 
23
  1. Create a custom post type called **Due Date**.
25
  1. Edit all the pages where the due date occurs and use the *Insert Pages* toolbar button to insert a reference to the *Due Date* you just created. Be sure to set the *Display* to **Content** so *Fri Nov 22, 2013* shows wherever you insert it. The shortcode you just created should look something like this: `[insert page='assignment-1-due-date' display='content']`
26
  1. That's it! Now, when you want to change the due date, just edit the *Assignment 1 Due Date* custom post you created, and it will automatically be updated on all the pages you inserted it on.
27
 
28
+ ### Advanced Use
29
  Say your site has a lot of video content, and you want to include video transcripts and video lengths along with the videos wherever you show them. You could just paste the transcripts into the page content under the video, but then you'd have to do this on every page the video showed on. (It's also just a bad idea, architecturally!) With Insert Pages, you can use a custom post type and create a custom theme template to display your videos+transcripts+lengths just the way you want!
30
 
31
  1. Create a custom post type called **Video**.
86
 
87
  == Changelog ==
88
 
89
+ = 3.0.1 =
90
+ * Hotfix: Version 3 broke some plugin compatibility (most notably with Beaver Builder and Page Builder by SiteOrigin). This update should restore functionality.
91
+ * Hotfix: Version 3 broke some page displays (e.g., content, all). This update should restore functionality.
92
+
93
  = 3.0 =
94
+ * Hotfix: 2.9.1 broke extra classes added to the inserted page wrapper. Props @philipsacht!
95
  * Feature: Expose extra classes and inline status in tinymce dialog.
96
  * One more API change to insert_pages_wrap_content_filter (2nd parameter is a WP_Post now instead of an array of WP_Posts, since we only ever insert one page).
97
  Example 1: