Changeset 509979
- Timestamp:
- 02/24/2012 04:39:23 PM (14 years ago)
- Location:
- page-specific-sidebars
- Files:
-
- 7 added
- 5 edited
-
tags/1.0 (added)
-
tags/1.0/Read.ME (added)
-
tags/1.0/gpl-3.0.txt (added)
-
tags/1.0/page-sidebar.php (added)
-
tags/1.0/readme.txt (added)
-
tags/1.0/screenshot-1.png (added)
-
tags/1.0/screenshot-2.png (added)
-
tags/2.0/Read.ME (modified) (1 diff)
-
tags/2.0/readme.txt (modified) (1 diff)
-
trunk/Read.ME (modified) (1 diff)
-
trunk/page-sidebar.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
page-specific-sidebars/tags/2.0/Read.ME
r509975 r509979 4 4 Requires at least: 3.0 5 5 Tested up to: 3.1 6 Stable tag: 1.0.06 Stable tag: 2.0 7 7 8 8 ==Short Description == -
page-specific-sidebars/tags/2.0/readme.txt
r509975 r509979 4 4 Requires at least: 3.0 5 5 Tested up to: 3.1 6 Stable tag: 1.0.06 Stable tag: 2.0 7 7 8 8 ==Short Description == -
page-specific-sidebars/trunk/Read.ME
r388109 r509979 4 4 Requires at least: 3.0 5 5 Tested up to: 3.1 6 Stable tag: 1.0.06 Stable tag: 2.0 7 7 8 8 ==Short Description == -
page-specific-sidebars/trunk/page-sidebar.php
r394757 r509979 4 4 * Plugin Name: Simple Page Specific Sidebars 5 5 * Author: dgilfoy, ivycat 6 * Description: Allows a page to be assigned a special sidebar. Either overwrites the generic sidebar call or adds 6 * Description: Allows a page to be assigned a special sidebar. Either overwrites the generic sidebar call or adds. For targeting Sidebars by name, see plugin option page 7 7 * to the existing generic sidebar 8 * Version: 1.0.18 * Version: 2.0 9 9 **/ 10 10 … … 32 32 class DGPageSidebarCustom{ 33 33 34 protected $home_id; 35 protected $widget_name; 36 34 37 public function __construct(){ 38 self::set_opts(); 35 39 add_action( 'widgets_init', array( &$this, 'build_sidebars' ) ); 36 40 add_action( 'admin_init', array( &$this, 'add_page_meta_box' ) ); 37 41 add_action( 'save_post' , array( &$this, 'save_custom_page_meta' ) ); 38 42 add_filter( 'sidebars_widgets', array( &$this, 'hijack_sidebar' ) ); 39 43 add_action('admin_menu', array(&$this, 'options_page_init') ); 44 } 45 46 /** 47 * Initialize the options page 48 */ 49 public function options_page_init(){ 50 if( !current_user_can( 'administrator' ) ) return; 51 add_options_page(__('Page Sidebar Settings'), __('Page Sidebar Settings'), 'read', 'page-sidebar-settings', array($this, 'option_page')); 52 } 53 54 /** 55 * Display Options page / Save Options on submit 56 */ 57 public function option_page(){ 58 if( $_SERVER['REQUEST_METHOD'] == 'POST' ) self::page_sidebar_settings_save(); 59 require_once 'views/page-sidebar-options-view.php'; 60 } 61 62 public function page_sidebar_settings_save(){ 63 update_option( 'page_sidebar_home_id', trim( $_POST['home_page_id'] ) ); 64 update_option( 'page_sidebar_widget_name', trim( $_POST['primary_sidebar_slug'] ) ); 65 self::set_opts(); 66 } 67 68 public function set_opts(){ 69 $this->home_pg_id = ( $home = get_option( 'page_sidebar_home_id' ) ) ? $home : self::home_pg_id(); 70 $this->widget_name = ( $widget = get_option( 'page_sidebar_widget_name' ) ) ? trim( $widget ) : 'sidebar-1'; 40 71 } 41 72 … … 105 136 } 106 137 107 public function hijack_sidebar( $sidebars ){138 public function hijack_sidebar( $sidebars=array() ){ 108 139 global $wp_registered_widgets, $wp_registered_sidebars, $_wp_sidebars_widgets, $post; 109 140 $sidebar_title = apply_filters( 'page-sidebar-title' , $this->widget_name ); 110 141 if( !is_page() || is_admin() ) return $sidebars; 111 142 $is_custom = get_post_meta( $post->ID, 'is_custom', true ); … … 122 153 }else{ 123 154 if( $sidebars_widgets['array_version'] != 3 ) return $sidebars; 124 if( $add2sidebar ){ 125 $sidebars['sidebar-1'] = array_merge( $sidebars['sidebar-1'], $_wp_sidebars_widgets[$sidebar_term] ); 126 155 if( $add2sidebar ){ 156 $sidebars[$sidebar_title] = ( is_array( $_wp_sidebars_widgets[$sidebar_term] ) ) ? array_merge( (array)$sidebars[$sidebar_title], $_wp_sidebars_widgets[$sidebar_term] ) : $sidebars[$sidebar_title]; 127 157 }else{ 128 $sidebars[ 'sidebar-1'] = $_wp_sidebars_widgets[$sidebar_term];158 $sidebars[$sidebar_title] = $_wp_sidebars_widgets[$sidebar_term]; 129 159 } 130 160 return $sidebars; … … 133 163 } 134 164 165 protected function fprint_r($array){ 166 printf('<pre>%s</pre>', print_r($array, 1)); 167 } 168 169 /** 170 * Often times the Homepage has posts on it, dictated by the template. For some reason, this sets the post->ID for the page as the last post listed on the page 171 * which keeps this plugin from inserting the correct sidebar. This is the fix. 172 */ 135 173 protected function home_pg_id(){ 174 $home_slug = 'home'; 136 175 $home_slug = apply_filters( 'page-sidebar-homeslug', $home_slug ); 137 176 $pg = get_page_by_path( $home_slug ); -
page-specific-sidebars/trunk/readme.txt
r394757 r509979 4 4 Requires at least: 3.0 5 5 Tested up to: 3.1 6 Stable tag: 1.0.06 Stable tag: 2.0 7 7 8 8 ==Short Description ==
Note: See TracChangeset
for help on using the changeset viewer.