Insert Pages - Version 3.1.5

Version Description

  • Fix for php warning when inserting page outside of The Loop while using Beaver Builder. Props @jeffreytanuwidjaja for the report.
Download this release

Release Info

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

Code changes from version 3.1.4 to 3.1.5

Files changed (2) hide show
  1. insert-pages.php +41 -8
  2. readme.txt +4 -1
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.1.4
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
@@ -121,7 +121,10 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
121
  }
122
 
123
  // Trying to embed same page in itself.
124
- if ( $attributes['page'] == $post->ID || $attributes['page'] == $post->post_name ) {
 
 
 
125
  return $content;
126
  }
127
 
@@ -217,10 +220,25 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
217
  // Note: Temporarily set the global $post->ID to the inserted page ID,
218
  // since Beaver Builder relies on it to load the appropriate styles.
219
  if ( class_exists( 'FLBuilder' ) ) {
220
- $old_post_id = $post->ID;
221
- $post->ID = $inserted_page->ID;
 
 
 
 
 
 
 
 
 
 
222
  FLBuilder::enqueue_layout_styles_scripts( $inserted_page->ID );
223
- $post->ID = $old_post_id;
 
 
 
 
 
224
  }
225
 
226
  // Show either the title, link, content, everything, or everything via a custom template
@@ -357,10 +375,25 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
357
  // Note: Temporarily set the global $post->ID to the inserted page ID,
358
  // since Beaver Builder relies on it to load the appropriate styles.
359
  if ( class_exists( 'FLBuilder' ) ) {
360
- $old_post_id = $post->ID;
361
- $post->ID = $inserted_page->ID;
 
 
 
 
 
 
 
 
 
 
362
  FLBuilder::enqueue_layout_styles_scripts( $inserted_page->ID );
363
- $post->ID = $old_post_id;
 
 
 
 
 
364
  }
365
 
366
  // Show either the title, link, content, everything, or everything via a custom template
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.1.5
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
121
  }
122
 
123
  // Trying to embed same page in itself.
124
+ if (
125
+ ! is_null( $post ) && property_exists( $post, 'ID' ) &&
126
+ ( $attributes['page'] == $post->ID || $attributes['page'] == $post->post_name )
127
+ ) {
128
  return $content;
129
  }
130
 
220
  // Note: Temporarily set the global $post->ID to the inserted page ID,
221
  // since Beaver Builder relies on it to load the appropriate styles.
222
  if ( class_exists( 'FLBuilder' ) ) {
223
+ // If we're not in The Loop (i.e., global $post isn't assigned),
224
+ // temporarily populate it with the post to be inserted so we can
225
+ // retrieve Beaver Builder styles for that post. Reset $post to null
226
+ // after we're done.
227
+ if ( is_null( $post ) ) {
228
+ $old_post_id = null;
229
+ $post = $inserted_page;
230
+ } else {
231
+ $old_post_id = $post->ID;
232
+ $post->ID = $inserted_page->ID;
233
+ }
234
+
235
  FLBuilder::enqueue_layout_styles_scripts( $inserted_page->ID );
236
+
237
+ if ( is_null( $old_post_id ) ) {
238
+ $post = null;
239
+ } else {
240
+ $post->ID = $old_post_id;
241
+ }
242
  }
243
 
244
  // Show either the title, link, content, everything, or everything via a custom template
375
  // Note: Temporarily set the global $post->ID to the inserted page ID,
376
  // since Beaver Builder relies on it to load the appropriate styles.
377
  if ( class_exists( 'FLBuilder' ) ) {
378
+ // If we're not in The Loop (i.e., global $post isn't assigned),
379
+ // temporarily populate it with the post to be inserted so we can
380
+ // retrieve Beaver Builder styles for that post. Reset $post to null
381
+ // after we're done.
382
+ if ( is_null( $post ) ) {
383
+ $old_post_id = null;
384
+ $post = $inserted_page;
385
+ } else {
386
+ $old_post_id = $post->ID;
387
+ $post->ID = $inserted_page->ID;
388
+ }
389
+
390
  FLBuilder::enqueue_layout_styles_scripts( $inserted_page->ID );
391
+
392
+ if ( is_null( $old_post_id ) ) {
393
+ $post = null;
394
+ } else {
395
+ $post->ID = $old_post_id;
396
+ }
397
  }
398
 
399
  // Show either the title, link, content, everything, or everything via a custom template
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: figureone, the_magician
3
  Tags: insert, pages, shortcode, embed
4
  Requires at least: 3.0.1
5
- Tested up to: 4.5.1
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -86,6 +86,9 @@ Just one! The plugin prevents you from embedding a page in itself, but you can t
86
 
87
  == Changelog ==
88
 
 
 
 
89
  = 3.1.4 =
90
  * Compatibility for for php versions lower than 5.3. Replace closure with create_function().
91
 
2
  Contributors: figureone, the_magician
3
  Tags: insert, pages, shortcode, embed
4
  Requires at least: 3.0.1
5
+ Tested up to: 4.5.3
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
86
 
87
  == Changelog ==
88
 
89
+ = 3.1.5 =
90
+ * Fix for php warning when inserting page outside of The Loop while using Beaver Builder. Props @jeffreytanuwidjaja for the report.
91
+
92
  = 3.1.4 =
93
  * Compatibility for for php versions lower than 5.3. Replace closure with create_function().
94