Insert Pages - Version 2.7.2

Version Description

  • Add shortcode attribute to wrap inserted content in an inline element (span) instead of a block level element (div). Example usage: Lorem ipsum [insert page='my-page' display='content' inline] dolor sit amet.
  • Add filter to wrap inserted content in an inline element (span) instead of a block level element (div). Example usage: function theme_init() { // Show a message in place of an inserted page if that page cannot be found. add_filter( 'insert_pages_use_inline_wrapper', function ( $should_use_inline_wrapper ) { return true; } ); } add_action( 'init', 'theme_init' );
Download this release

Release Info

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

Code changes from version 2.7.1 to 2.7.2

Files changed (2) hide show
  1. insert-pages.php +47 -25
  2. readme.txt +11 -1
insert-pages.php CHANGED
@@ -5,7 +5,7 @@ Plugin Name: Insert Pages
5
  Plugin URI: https://bitbucket.org/figureone/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: 2.7.1
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
@@ -102,6 +102,7 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
102
  'page' => '0',
103
  'display' => 'all',
104
  'class' => '',
 
105
  ), $atts ) );
106
 
107
  // Validation checks.
@@ -168,6 +169,20 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
168
  */
169
  $should_apply_the_content_filter = apply_filters( 'insert_pages_apply_the_content_filter', $should_apply_the_content_filter );
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  // Start our new Loop (only iterate once).
172
  if ( have_posts() ) {
173
  ob_start(); // Start output buffering so we can save the output to string
@@ -179,39 +194,45 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
179
  // the inserted page. @see https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage
180
  switch ( $display ) {
181
  case "title":
182
- the_post(); ?>
183
- <h1><?php the_title(); ?></h1>
184
- <?php break;
 
 
 
185
  case "link":
186
- the_post(); ?>
187
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
188
- <?php break;
189
  case "excerpt":
190
- the_post(); ?>
191
- <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
192
- <?php if ( $should_apply_the_content_filter ) the_excerpt(); else echo get_the_excerpt(); ?>
193
- <?php break;
194
  case "excerpt-only":
195
- the_post(); ?>
196
- <?php if ( $should_apply_the_content_filter ) the_excerpt(); else echo get_the_excerpt(); ?>
197
- <?php break;
198
  case "content":
199
- the_post(); ?>
200
- <?php if ( $should_apply_the_content_filter ) the_content(); else echo get_the_content(); ?>
201
- <?php break;
202
  case "all":
203
- the_post(); ?>
204
- <h1><?php the_title(); ?></h1>
205
- <?php if ( $should_apply_the_content_filter ) the_content(); else echo get_the_content(); ?>
206
- <?php the_meta(); ?>
207
- <?php break;
 
 
 
208
  default: // display is either invalid, or contains a template file to use
209
  $template = locate_template( $display );
210
  if ( strlen( $template ) > 0 ) {
211
  include $template; // execute the template code
212
  } else { // Couldn't find template, so fall back to printing a link to the page.
213
- the_post(); ?>
214
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
215
  }
216
  break;
217
  }
@@ -229,7 +250,8 @@ if ( !class_exists( 'InsertPagesPlugin' ) ) {
229
 
230
  wp_reset_query();
231
 
232
- $content = "<div data-post-id='$page' class='insert-page insert-page-$page $class'>$content</div>";
 
233
  return $content;
234
  //return do_shortcode($content); // careful: watch for infinite loops with nested inserts
235
  }
5
  Plugin URI: https://bitbucket.org/figureone/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: 2.7.2
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
102
  'page' => '0',
103
  'display' => 'all',
104
  'class' => '',
105
+ 'inline' => false,
106
  ), $atts ) );
107
 
108
  // Validation checks.
169
  */
170
  $should_apply_the_content_filter = apply_filters( 'insert_pages_apply_the_content_filter', $should_apply_the_content_filter );
171
 
172
+ $should_use_inline_wrapper = ( $inline !== false && $inline !== 'false' ) || array_search( 'inline', $atts ) === 0;
173
+ /**
174
+ * Filter the flag indicating whether to wrap the inserted content in inline tags (span).
175
+ *
176
+ * @param bool $use_inline_wrapper Indicates whether to wrap the content in span tags.
177
+ */
178
+ $should_use_inline_wrapper = apply_filters( 'insert_pages_use_inline_wrapper', $should_use_inline_wrapper );
179
+
180
+ // Disable the_content filter if using inline tags, since wpautop
181
+ // inserts p tags and we can't have any inside inline elements.
182
+ if ( $should_use_inline_wrapper ) {
183
+ $should_apply_the_content_filter = false;
184
+ }
185
+
186
  // Start our new Loop (only iterate once).
187
  if ( have_posts() ) {
188
  ob_start(); // Start output buffering so we can save the output to string
194
  // the inserted page. @see https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage
195
  switch ( $display ) {
196
  case "title":
197
+ the_post();
198
+ $title_tag = $should_use_inline_wrapper ? 'span' : 'h1';
199
+ echo "<$title_tag class='insert-page-title'>";
200
+ the_title();
201
+ echo "</$title_tag>";
202
+ break;
203
  case "link":
204
+ the_post();
205
+ ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
206
+ break;
207
  case "excerpt":
208
+ the_post();
209
+ ?><h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1><?php
210
+ if ( $should_apply_the_content_filter ) the_excerpt(); else echo get_the_excerpt();
211
+ break;
212
  case "excerpt-only":
213
+ the_post();
214
+ if ( $should_apply_the_content_filter ) the_excerpt(); else echo get_the_excerpt();
215
+ break;
216
  case "content":
217
+ the_post();
218
+ if ( $should_apply_the_content_filter ) the_content(); else echo get_the_content();
219
+ break;
220
  case "all":
221
+ the_post();
222
+ $title_tag = $should_use_inline_wrapper ? 'span' : 'h1';
223
+ echo "<$title_tag class='insert-page-title'>";
224
+ the_title();
225
+ echo "</$title_tag>";
226
+ if ( $should_apply_the_content_filter ) the_content(); else echo get_the_content();
227
+ the_meta();
228
+ break;
229
  default: // display is either invalid, or contains a template file to use
230
  $template = locate_template( $display );
231
  if ( strlen( $template ) > 0 ) {
232
  include $template; // execute the template code
233
  } else { // Couldn't find template, so fall back to printing a link to the page.
234
+ the_post();
235
+ ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
236
  }
237
  break;
238
  }
250
 
251
  wp_reset_query();
252
 
253
+ $wrapper_tag = $should_use_inline_wrapper ? 'span' : 'div';
254
+ $content = "<$wrapper_tag data-post-id='$page' class='insert-page insert-page-$page $class'>$content</$wrapper_tag>";
255
  return $content;
256
  //return do_shortcode($content); // careful: watch for infinite loops with nested inserts
257
  }
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.2.2
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -86,6 +86,16 @@ Just one! The plugin prevents you from embedding a page in itself, but you can t
86
 
87
  == Changelog ==
88
 
 
 
 
 
 
 
 
 
 
 
89
  = 2.7.1 =
90
  * Add filter to show a message when an inserted page cannot be found. Example usage:
91
  `function theme_init() {
2
  Contributors: figureone, the_magician
3
  Tags: insert, pages, shortcode, embed
4
  Requires at least: 3.0.1
5
+ Tested up to: 4.3.1
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
+ = 2.7.2 =
90
+ * Add shortcode attribute to wrap inserted content in an inline element (span) instead of a block level element (div). Example usage:
91
+ `Lorem ipsum [insert page='my-page' display='content' inline] dolor sit amet.`
92
+ * Add filter to wrap inserted content in an inline element (span) instead of a block level element (div). Example usage:
93
+ `function theme_init() {
94
+ // Show a message in place of an inserted page if that page cannot be found.
95
+ add_filter( 'insert_pages_use_inline_wrapper', function ( $should_use_inline_wrapper ) { return true; } );
96
+ }
97
+ add_action( 'init', 'theme_init' );`
98
+
99
  = 2.7.1 =
100
  * Add filter to show a message when an inserted page cannot be found. Example usage:
101
  `function theme_init() {