Insert Pages - Version 3.1

Version Description

  • Feature: Insert Page widget. Go to Appearance > Widgets to add the Insert Page widget to any of your widget areas. Specify a page slug or ID in the widget, and that page will get displayed in the widget area.
Download this release

Release Info

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

Code changes from version 3.0.2 to 3.1

Files changed (5) hide show
  1. insert-pages.php +5 -1
  2. js/widget.js +18 -0
  3. js/wpinsertpages.js +4 -3
  4. readme.txt +3 -0
  5. widget.php +123 -0
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.2
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
@@ -763,4 +763,8 @@ if ( isset( $insertPages_plugin ) ) {
763
 
764
  // Use internal filter to wrap inserted content in a div or span.
765
  add_filter( 'insert_pages_wrap_content', array( $insertPages_plugin, 'insertPages_wrap_content' ), 10, 3 );
 
 
 
 
766
  }
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
9
  Author URI: http://www.linkedin.com/in/paulrryan
10
  License: GPL2
11
  */
763
 
764
  // Use internal filter to wrap inserted content in a div or span.
765
  add_filter( 'insert_pages_wrap_content', array( $insertPages_plugin, 'insertPages_wrap_content' ), 10, 3 );
766
+
767
+ // Register Insert Pages shortcode widget.
768
+ require_once( dirname( __FILE__ ) . '/widget.php' );
769
+ add_action( 'widgets_init', function () { return register_widget( 'InsertPagesWidget' ); } );
770
  }
js/widget.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).ready( function ( $ ) {
2
+ // Enable/Disable template dropdown based on display choice in widget options.
3
+ $( document ).on( 'change', '.insertpage-format-select', function() {
4
+ if ( $( this ).val() == 'template' ) {
5
+ $( '.insertpage-template-select' ).removeAttr( 'disabled' );
6
+ if ( $( this ).is( ':focus' ) ) {
7
+ $( '.insertpage-template-select' ).focus();
8
+ }
9
+ } else {
10
+ $( '.insertpage-template-select' ).attr( 'disabled', 'disabled' );
11
+ }
12
+ });
13
+ $( document ).on( 'widget-updated', function () {
14
+ $( '.insertpage-format-select' ).change();
15
+ })
16
+ $( '.insertpage-format-select' ).change();
17
+
18
+ });
js/wpinsertpages.js CHANGED
@@ -2,7 +2,7 @@
2
  /* global ajaxurl, tinymce, wpLinkL10n, setUserSetting, wpActiveEditor */
3
  var wpInsertPages;
4
 
5
- (function($){
6
  var inputs = {}, rivers = {}, editor, searchTimer, RiverInsertPages, QueryInsertPages;
7
 
8
  wpInsertPages = {
@@ -631,5 +631,6 @@ var wpInsertPages;
631
  }
632
  });
633
 
634
- $(document).ready( wpInsertPages.init );
635
- })(jQuery);
 
2
  /* global ajaxurl, tinymce, wpLinkL10n, setUserSetting, wpActiveEditor */
3
  var wpInsertPages;
4
 
5
+ (function ( $ ) {
6
  var inputs = {}, rivers = {}, editor, searchTimer, RiverInsertPages, QueryInsertPages;
7
 
8
  wpInsertPages = {
631
  }
632
  });
633
 
634
+ $( document ).ready( wpInsertPages.init );
635
+
636
+ })( jQuery );
readme.txt CHANGED
@@ -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.0.2 =
90
  * Hotfix: Inserting posts with custom paths using legacy insert method.
91
 
86
 
87
  == Changelog ==
88
 
89
+ = 3.1 =
90
+ * Feature: Insert Page widget. Go to Appearance > Widgets to add the Insert Page widget to any of your widget areas. Specify a page slug or ID in the widget, and that page will get displayed in the widget area.
91
+
92
  = 3.0.2 =
93
  * Hotfix: Inserting posts with custom paths using legacy insert method.
94
 
widget.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class: InsertPagesWidget extends WP_Widget
5
+ * Provides a widget for inserting a page into a widget area.
6
+ */
7
+
8
+ class InsertPagesWidget extends WP_Widget {
9
+
10
+ /**
11
+ * Set up the widget.
12
+ */
13
+ public function __construct() {
14
+ // Load admin javascript for Widget options.
15
+ if ( is_admin() ) {
16
+ wp_enqueue_script( 'insertpages_widget', plugins_url( '/js/widget.js', __FILE__ ), array( 'jquery' ), '20160105' );
17
+ }
18
+
19
+ // Call parent constructor to initialize the widget.
20
+ parent::__construct( 'ipw', 'Insert Page', array( 'description' => 'Insert a page into a widget area.' ) );
21
+ }
22
+
23
+ /**
24
+ * Output the content of the widget.
25
+ *
26
+ * @param array $args
27
+ * @param array $instance
28
+ */
29
+ public function widget( $args, $instance ) {
30
+ global $insertPages_plugin;
31
+
32
+ // Print widget wrapper.
33
+ echo $args['before_widget'];
34
+
35
+ // Build the shortcode attributes array from the widget args.
36
+ $atts = array();
37
+ if ( array_key_exists( 'page', $instance ) ) {
38
+ $atts['page'] = $instance['page'];
39
+ }
40
+ if ( array_key_exists( 'display', $instance ) ) {
41
+ $atts['display'] = $instance['display'];
42
+ }
43
+ if ( array_key_exists( 'template', $instance ) && $instance['display'] === 'template' ) {
44
+ $atts['display'] = $instance['template'];
45
+ }
46
+ if ( array_key_exists( 'class', $instance ) ) {
47
+ $atts['class'] = $instance['class'];
48
+ }
49
+ if ( array_key_exists( 'inline', $instance ) ) {
50
+ $atts['inline'] = $instance['inline'] === '1';
51
+ }
52
+
53
+ // Render the inserted page using the plugin's shortcode handler.
54
+ $content = $insertPages_plugin->insertPages_handleShortcode_insert( $atts );
55
+
56
+ // Print inserted page.
57
+ echo $content;
58
+
59
+ // Print widget wrapper.
60
+ echo $args['after_widget'];
61
+ }
62
+
63
+ /**
64
+ * Output the options form on admin.
65
+ *
66
+ * @param array $instance The widget options
67
+ */
68
+ public function form( $instance ) {
69
+ $instance = wp_parse_args( (array)$instance, array(
70
+ 'page' => '',
71
+ 'display' => 'link',
72
+ 'template' => '',
73
+ 'class' => '',
74
+ 'inline' => '',
75
+ )); ?>
76
+ <p>
77
+ <label for="<?php echo $this->get_field_id( 'page' ); ?>"><?php _e( 'Page/Post ID or Slug' ); ?>:</label>
78
+ <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'page' ); ?>" name="<?php echo $this->get_field_name( 'page' ); ?>" value="<?php echo $instance['page']; ?>" />
79
+ </p>
80
+ <p>
81
+ <label for="<?php echo $this->get_field_id( 'display' ); ?>"><?php _e( 'Display' ); ?>:</label><br />
82
+ <select class="insertpage-format-select" name="<?php echo $this->get_field_name( 'display' ); ?>" id="<?php echo $this->get_field_id( 'display' ); ?>">
83
+ <option value='title' <?php selected( $instance['display'], 'title' ); ?>>Title</option>
84
+ <option value='link' <?php selected( $instance['display'], 'link' ); ?>>Link</option>
85
+ <option value='excerpt' <?php selected( $instance['display'], 'excerpt' ); ?>>Excerpt</option>
86
+ <option value='excerpt-only' <?php selected( $instance['display'], 'excerpt-only' ); ?>>Excerpt only (no title)</option>
87
+ <option value='content' <?php selected( $instance['display'], 'content' ); ?>>Content</option>
88
+ <option value='all' <?php selected( $instance['display'], 'all' ); ?>>All (includes custom fields)</option>
89
+ <option value='template' <?php selected( $instance['display'], 'template' ); ?>>Use a custom template &raquo;</option>
90
+ </select>
91
+ <select class="insertpage-template-select" name="<?php echo $this->get_field_name( 'template' ); ?>" id="<?php echo $this->get_field_id( 'template' ); ?>" disabled="disabled">
92
+ <option value='all'><?php _e( 'Default Template' ); ?></option>
93
+ <?php page_template_dropdown( $instance['template'] ); ?>
94
+ </select>
95
+ </p>
96
+ <p>
97
+ <label for="<?php echo $this->get_field_id( 'class' ); ?>"><?php _e( 'Extra Classes' ); ?>:</label>
98
+ <input type="text" class="widefat" autocomplete="off" name="<?php echo $this->get_field_name( 'class' ); ?>" id="<?php echo $this->get_field_id( 'class' ); ?>" value="<?php echo esc_attr( $instance['class'] ); ?>" />
99
+ </p>
100
+ <p>
101
+ <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name( 'inline' ); ?>" id="<?php echo $this->get_field_id( 'inline' ); ?>" value="1" <?php checked( $instance['inline'], '1' ); ?> />
102
+ <label for="<?php echo $this->get_field_id( 'inline' ); ?>"><?php _e( 'Inline?' ); ?></label>
103
+ </p><?php
104
+ }
105
+
106
+ /**
107
+ * Process widget options on save.
108
+ *
109
+ * @param array $new_instance The new options
110
+ * @param array $old_instance The previous options
111
+ */
112
+ public function update( $new_instance, $old_instance ) {
113
+ // Sanitize form options.
114
+ $instance = $old_instance;
115
+ $instance['page'] = strip_tags( $new_instance['page'] );
116
+ $instance['display'] = strip_tags( $new_instance['display'] );
117
+ $instance['template'] = strip_tags( $new_instance['template'] );
118
+ $instance['class'] = strip_tags( $new_instance['class'] );
119
+ $instance['inline'] = strip_tags( $new_instance['inline'] );
120
+
121
+ return $instance;
122
+ }
123
+ }