Simple Page Sidebars - Version 1.1.1

Version Description

  • Worked around the slashing weirdness in WordPress API.
  • Implemented a method to allow developers to easily add support for additional post types. No plans to build this out further, it's just here for additional flexibility if more complex solutions aren't wanted.
  • Added a filter to disable the edit link in the custom Sidebar column (simple_page_sidebars_show_edit_link_in_column).
Download this release

Release Info

Developer blazersix
Plugin Icon 128x128 Simple Page Sidebars
Version 1.1.1
Comparing to
See all releases

Code changes from version 1.1 to 1.1.1

admin/admin.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * @package Simple Page Sidebars
4
- * @subpackage Simple Page Sidebars Admin
5
  *
6
  * @todo Consider adding a Sidebars submenu to the Appearance menu for
7
  * selecting and editing a sidebar.
@@ -40,8 +39,8 @@ class Simple_Page_Sidebars_Admin {
40
  // Process quick edit and bulk edit from All Pages screen.
41
  add_action( 'wp_ajax_simplepagesidebars_update_page_sidebar', array( __CLASS__, 'update_page_sidebar' ) );
42
 
43
- add_action( 'admin_menu', array( __CLASS__, 'add_page_sidebar_meta_box' ) );
44
  add_action( 'admin_menu', array( __CLASS__, 'add_sidebar_edit_screen' ) );
 
45
 
46
  add_action( 'admin_init', array( __CLASS__, 'register_default_sidebar_setting' ) );
47
 
@@ -112,8 +111,10 @@ class Simple_Page_Sidebars_Admin {
112
  *
113
  * @since 0.2.0
114
  */
115
- public static function add_page_sidebar_meta_box() {
116
- add_meta_box( 'simplepagesidebarsdiv', __( 'Sidebar', 'simple-page-sidebars' ), array( __CLASS__, 'page_sidebar_meta_box' ), 'page', 'side', 'default' );
 
 
117
  }
118
 
119
  /**
@@ -208,10 +209,15 @@ class Simple_Page_Sidebars_Admin {
208
  if ( 'simple-page-sidebar' == $column ) {
209
  $sidebar = self::get_page_sidebar( $page_id );
210
  if ( $sidebar ) {
211
- printf( '<a href="%s">%s</a>',
212
- esc_url( self::get_sidebar_edit_link( $sidebar ) ),
213
- $sidebar
214
- );
 
 
 
 
 
215
  }
216
 
217
  // Add the nonce here and copy it to the inline editor with javascript.
@@ -396,7 +402,7 @@ class Simple_Page_Sidebars_Admin {
396
  * @param string $parent_file The top level menu item being viewed.
397
  * @return string $parent_file
398
  */
399
- function highlight_widget_submenu( $parent_file ) {
400
  global $submenu_file;
401
 
402
  $screen = get_current_screen();
@@ -422,7 +428,7 @@ class Simple_Page_Sidebars_Admin {
422
  wp_enqueue_script( 'post' );
423
 
424
  $screen = get_current_screen();
425
- $sidebar_name = self::sanitize_sidebar_name( $_GET['sidebar'] );
426
 
427
  include( SIMPLE_PAGE_SIDEBARS_DIR . 'admin/views/edit-sidebar-screen.php' );
428
  }
@@ -450,12 +456,14 @@ class Simple_Page_Sidebars_Admin {
450
  * @since 1.1.0
451
  */
452
  public static function process_sidebar_update() {
 
 
453
  if ( isset( $_POST['simplepagesidebars_sidebar_name'] ) ) {
454
- $current_name = $_POST['simplepagesidebars_sidebar_name'];
455
 
456
  check_admin_referer( 'update-sidebar_' . $current_name, 'simplepagesidebars_sidebar_update_nonce' );
457
 
458
- $new_name = $_POST['simplepagesidebars_sidebar_name_new'];
459
  $new_name = ( ! empty( $new_name ) && $new_name != $current_name ) ? trim( wp_strip_all_tags( $new_name ) ) : null;
460
 
461
  $pages = ( isset( $_POST['simplepagesidebars_sidebar_pages'] ) ) ? wp_parse_id_list( $_POST['simplepagesidebars_sidebar_pages'] ) : array();
@@ -471,16 +479,14 @@ class Simple_Page_Sidebars_Admin {
471
  }
472
  }
473
 
474
- // Update submitted page sidebars if there is a new sidebar name.
475
- if ( $new_name && ! empty( $pages ) ) {
476
- foreach( $pages as $page_id ) {
477
- update_post_meta( $page_id, '_sidebar_name', $new_name );
478
- }
479
  }
480
  // Update newly selected pages with the current sidebar name.
481
  elseif ( $update_pages = array_diff( $pages, $current_pages ) ) {
482
  foreach( $update_pages as $page_id ) {
483
- update_post_meta( $page_id, '_sidebar_name', $current_name );
484
  }
485
  }
486
 
1
  <?php
2
  /**
3
+ * @package Simple_Page_Sidebars
 
4
  *
5
  * @todo Consider adding a Sidebars submenu to the Appearance menu for
6
  * selecting and editing a sidebar.
39
  // Process quick edit and bulk edit from All Pages screen.
40
  add_action( 'wp_ajax_simplepagesidebars_update_page_sidebar', array( __CLASS__, 'update_page_sidebar' ) );
41
 
 
42
  add_action( 'admin_menu', array( __CLASS__, 'add_sidebar_edit_screen' ) );
43
+ add_action( 'add_meta_boxes', array( __CLASS__, 'add_page_sidebar_meta_box' ) );
44
 
45
  add_action( 'admin_init', array( __CLASS__, 'register_default_sidebar_setting' ) );
46
 
111
  *
112
  * @since 0.2.0
113
  */
114
+ public static function add_page_sidebar_meta_box( $post_type ) {
115
+ if ( 'page' == $post_type || post_type_supports( $post_type, 'simple-page-sidebars' ) ) {
116
+ add_meta_box( 'simplepagesidebarsdiv', __( 'Sidebar', 'simple-page-sidebars' ), array( __CLASS__, 'page_sidebar_meta_box' ), $post_type, 'side', 'default' );
117
+ }
118
  }
119
 
120
  /**
209
  if ( 'simple-page-sidebar' == $column ) {
210
  $sidebar = self::get_page_sidebar( $page_id );
211
  if ( $sidebar ) {
212
+ // The edit link can be disabled to prevent confusion if support is added to other post types.
213
+ if ( apply_filters( 'simple_page_sidebars_show_edit_link_in_column', true ) ) {
214
+ printf( '<a href="%s">%s</a>',
215
+ esc_url( self::get_sidebar_edit_link( $sidebar ) ),
216
+ $sidebar
217
+ );
218
+ } else {
219
+ echo $sidebar;
220
+ }
221
  }
222
 
223
  // Add the nonce here and copy it to the inline editor with javascript.
402
  * @param string $parent_file The top level menu item being viewed.
403
  * @return string $parent_file
404
  */
405
+ public static function highlight_widget_submenu( $parent_file ) {
406
  global $submenu_file;
407
 
408
  $screen = get_current_screen();
428
  wp_enqueue_script( 'post' );
429
 
430
  $screen = get_current_screen();
431
+ $sidebar_name = self::sanitize_sidebar_name( stripslashes( $_GET['sidebar'] ) );
432
 
433
  include( SIMPLE_PAGE_SIDEBARS_DIR . 'admin/views/edit-sidebar-screen.php' );
434
  }
456
  * @since 1.1.0
457
  */
458
  public static function process_sidebar_update() {
459
+ global $wpdb;
460
+
461
  if ( isset( $_POST['simplepagesidebars_sidebar_name'] ) ) {
462
+ $current_name = stripslashes( $_POST['simplepagesidebars_sidebar_name'] );
463
 
464
  check_admin_referer( 'update-sidebar_' . $current_name, 'simplepagesidebars_sidebar_update_nonce' );
465
 
466
+ $new_name = stripslashes( $_POST['simplepagesidebars_sidebar_name_new'] );
467
  $new_name = ( ! empty( $new_name ) && $new_name != $current_name ) ? trim( wp_strip_all_tags( $new_name ) ) : null;
468
 
469
  $pages = ( isset( $_POST['simplepagesidebars_sidebar_pages'] ) ) ? wp_parse_id_list( $_POST['simplepagesidebars_sidebar_pages'] ) : array();
479
  }
480
  }
481
 
482
+ // Update all sidebars if there is a new sidebar name.
483
+ if ( $new_name ) {
484
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value=%s WHERE meta_key='_sidebar_name' AND meta_value=%s", $new_name, $current_name ) );
 
 
485
  }
486
  // Update newly selected pages with the current sidebar name.
487
  elseif ( $update_pages = array_diff( $pages, $current_pages ) ) {
488
  foreach( $update_pages as $page_id ) {
489
+ update_post_meta( $page_id, '_sidebar_name', addslashes( $current_name ) );
490
  }
491
  }
492
 
admin/views/meta-box-page-sidebar.php CHANGED
@@ -1,6 +1,6 @@
1
  <div id="simple-page-sidebars-page-sidebar-update-message" class="simple-page-sidebars-page-sidebar-feedback" style="display: none">
2
  <p>
3
- <?php _e( 'Page sidebar saved.', 'simple-page-sidebars' ); ?>
4
  <a href="<?php echo admin_url( 'widgets.php' ); ?>"><?php _e( 'Update widgets now.', 'simple-page-sidebars' ); ?></a>
5
  </p>
6
  </div>
1
  <div id="simple-page-sidebars-page-sidebar-update-message" class="simple-page-sidebars-page-sidebar-feedback" style="display: none">
2
  <p>
3
+ <?php _e( 'Sidebar saved.', 'simple-page-sidebars' ); ?>
4
  <a href="<?php echo admin_url( 'widgets.php' ); ?>"><?php _e( 'Update widgets now.', 'simple-page-sidebars' ); ?></a>
5
  </p>
6
  </div>
admin/views/meta-box-sidebar-pages.php CHANGED
@@ -19,7 +19,7 @@
19
  'cache_results' => false
20
  ) );
21
 
22
- $args['sidebar'] = self::sanitize_sidebar_name( $_GET['sidebar'] );
23
  $args['selected'] = self::get_page_ids_using_sidebar( $args['sidebar'] );
24
  $args['walker'] = new Simple_Page_Siders_Walker_Page_Checklist;
25
 
19
  'cache_results' => false
20
  ) );
21
 
22
+ $args['sidebar'] = self::sanitize_sidebar_name( stripslashes( $_GET['sidebar'] ) );
23
  $args['selected'] = self::get_page_ids_using_sidebar( $args['sidebar'] );
24
  $args['walker'] = new Simple_Page_Siders_Walker_Page_Checklist;
25
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://bit.ly/s2zcgD
4
  Tags: sidebars, custom sidebars, dynamic sidebar, simple, widget, widgets
5
  Requires at least: 3.4.2
6
  Tested up to: 3.5
7
- Stable tag: 1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -68,6 +68,11 @@ Some themes create different sidebars for their various page templates, which me
68
 
69
  == Changelog ==
70
 
 
 
 
 
 
71
  = 1.1 =
72
  * Added an Edit Sidebar screen for updating a sidebar name and associated pages.
73
  * Added an update message when a sidebar is saved on the Add/Edit Page screen.
4
  Tags: sidebars, custom sidebars, dynamic sidebar, simple, widget, widgets
5
  Requires at least: 3.4.2
6
  Tested up to: 3.5
7
+ Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
68
 
69
  == Changelog ==
70
 
71
+ = 1.1.1 =
72
+ * Worked around the slashing weirdness in WordPress API.
73
+ * Implemented a method to allow developers to easily add support for additional post types. No plans to build this out further, it's just here for additional flexibility if more complex solutions aren't wanted.
74
+ * Added a filter to disable the edit link in the custom Sidebar column (`simple_page_sidebars_show_edit_link_in_column`).
75
+
76
  = 1.1 =
77
  * Added an Edit Sidebar screen for updating a sidebar name and associated pages.
78
  * Added an update message when a sidebar is saved on the Add/Edit Page screen.
simple-page-sidebars.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Simple Page Sidebars
4
  * Plugin URI: http://wordpress.org/extend/plugins/simple-page-sidebars/
5
  * Description: Assign custom, widget-enabled sidebars to any page with ease.
6
- * Version: 1.1
7
  * Author: Blazer Six, Inc.
8
  * Author URI: http://www.blazersix.com/
9
  * License: GPLv2 or later
@@ -23,7 +23,7 @@
23
  * with this program; if not, write to the Free Software Foundation, Inc., 59
24
  * Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
  *
26
- * @package Simple Page Sidebars
27
  * @author Brady Vercher <brady@blazersix.com>
28
  * @copyright Copyright (c) 2012, Blazer Six, Inc.
29
  * @license http://www.gnu.org/licenses/gpl-2.0.html
@@ -118,10 +118,11 @@ class Simple_Page_Sidebars {
118
  // Override the default widget properties.
119
  $widget_area_defaults = array(
120
  'before_widget' => '<div id="%1$s" class="widget %2$s">',
121
- 'after_widget' => '</div>',
122
- 'before_title' => '<h4 class="title">',
123
- 'after_title' => '</h4>'
124
  );
 
125
  $widget_area_defaults = apply_filters( 'simple_page_sidebars_widget_defaults', $widget_area_defaults );
126
 
127
  // If any custom sidebars have been assigned to pages, merge them with already defined widget areas.
@@ -145,10 +146,10 @@ class Simple_Page_Sidebars {
145
  'id' => $key,
146
  'name' => $area['name'],
147
  'description' => $area['description'],
148
- 'before_widget' => ( ! isset( $area['before_widget'] ) ) ? $widget_area_defaults['before_widget'] : $area['before_widget'],
149
- 'after_widget' => ( ! isset( $area['after_widget'] ) ) ? $widget_area_defaults['after_widget'] : $area['after_widget'],
150
- 'before_title' => ( ! isset( $area['before_title'] ) ) ? $widget_area_defaults['before_title'] : $area['before_title'],
151
- 'after_title' => ( ! isset( $area['after_title'] ) ) ? $widget_area_defaults['after_title'] : $area['after_title']
152
  ));
153
  }
154
  }
@@ -163,7 +164,9 @@ class Simple_Page_Sidebars {
163
  public static function replace_sidebar( $sidebars_widgets ) {
164
  global $post;
165
 
166
- if ( is_page() || ( is_home() && $posts_page = get_option( 'page_for_posts' ) ) ) {
 
 
167
  $post_id = ( ! empty( $posts_page ) ) ? $posts_page : $post->ID;
168
 
169
  $custom_sidebar = get_post_meta( $post_id, '_sidebar_name', true );
@@ -209,11 +212,9 @@ class Simple_Page_Sidebars {
209
  function simple_page_sidebars_get_names() {
210
  global $wpdb;
211
 
212
- $sidebar_names = $wpdb->get_results( "SELECT meta_value
213
  FROM $wpdb->posts p, $wpdb->postmeta pm
214
- WHERE p.post_type='page' AND p.post_status!='auto-draft' AND p.ID=pm.post_id
215
- AND pm.meta_key='_sidebar_name'
216
- GROUP BY pm.meta_value
217
  ORDER BY pm.meta_value ASC" );
218
 
219
  $sidebars = array();
3
  * Plugin Name: Simple Page Sidebars
4
  * Plugin URI: http://wordpress.org/extend/plugins/simple-page-sidebars/
5
  * Description: Assign custom, widget-enabled sidebars to any page with ease.
6
+ * Version: 1.1.1
7
  * Author: Blazer Six, Inc.
8
  * Author URI: http://www.blazersix.com/
9
  * License: GPLv2 or later
23
  * with this program; if not, write to the Free Software Foundation, Inc., 59
24
  * Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
  *
26
+ * @package Simple_Page_Sidebars
27
  * @author Brady Vercher <brady@blazersix.com>
28
  * @copyright Copyright (c) 2012, Blazer Six, Inc.
29
  * @license http://www.gnu.org/licenses/gpl-2.0.html
118
  // Override the default widget properties.
119
  $widget_area_defaults = array(
120
  'before_widget' => '<div id="%1$s" class="widget %2$s">',
121
+ 'after_widget' => '</div>',
122
+ 'before_title' => '<h4 class="title">',
123
+ 'after_title' => '</h4>'
124
  );
125
+
126
  $widget_area_defaults = apply_filters( 'simple_page_sidebars_widget_defaults', $widget_area_defaults );
127
 
128
  // If any custom sidebars have been assigned to pages, merge them with already defined widget areas.
146
  'id' => $key,
147
  'name' => $area['name'],
148
  'description' => $area['description'],
149
+ 'before_widget' => ( isset( $area['before_widget'] ) ) ? $area['before_widget'] : $widget_area_defaults['before_widget'],
150
+ 'after_widget' => ( isset( $area['after_widget'] ) ) ? $area['after_widget'] : $widget_area_defaults['after_widget'],
151
+ 'before_title' => ( isset( $area['before_title'] ) ) ? $area['before_title'] : $widget_area_defaults['before_title'],
152
+ 'after_title' => ( isset( $area['after_title'] ) ) ? $area['after_title'] : $widget_area_defaults['after_title']
153
  ));
154
  }
155
  }
164
  public static function replace_sidebar( $sidebars_widgets ) {
165
  global $post;
166
 
167
+ $supports = ( isset( $post->post_type ) && post_type_supports( $post->post_type, 'simple-page-sidebars' ) ) ? true : false;
168
+
169
+ if ( is_page() || $supports || ( is_home() && $posts_page = get_option( 'page_for_posts' ) ) ) {
170
  $post_id = ( ! empty( $posts_page ) ) ? $posts_page : $post->ID;
171
 
172
  $custom_sidebar = get_post_meta( $post_id, '_sidebar_name', true );
212
  function simple_page_sidebars_get_names() {
213
  global $wpdb;
214
 
215
+ $sidebar_names = $wpdb->get_results( "SELECT DISTINCT meta_value
216
  FROM $wpdb->posts p, $wpdb->postmeta pm
217
+ WHERE p.post_status!='auto-draft' AND p.ID=pm.post_id AND pm.meta_key='_sidebar_name'
 
 
218
  ORDER BY pm.meta_value ASC" );
219
 
220
  $sidebars = array();
uninstall.php CHANGED
@@ -5,7 +5,7 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
5
 
6
  global $wpdb;
7
 
8
- $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key='_sidebar_name'");
9
  delete_option( 'simple_page_sidebars_default_sidebar' );
10
  delete_option( 'simple_page_sidebars_version' );
11
  ?>
5
 
6
  global $wpdb;
7
 
8
+ $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key='_sidebar_name'" );
9
  delete_option( 'simple_page_sidebars_default_sidebar' );
10
  delete_option( 'simple_page_sidebars_version' );
11
  ?>