Plugin Directory

Changeset 509979


Ignore:
Timestamp:
02/24/2012 04:39:23 PM (14 years ago)
Author:
dgilfoy
Message:

Moved 2.0 to the trunk

Location:
page-specific-sidebars
Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • page-specific-sidebars/tags/2.0/Read.ME

    r509975 r509979  
    44Requires at least: 3.0
    55Tested up to: 3.1
    6 Stable tag: 1.0.0
     6Stable tag:  2.0
    77
    88==Short Description ==
  • page-specific-sidebars/tags/2.0/readme.txt

    r509975 r509979  
    44Requires at least: 3.0
    55Tested up to: 3.1
    6 Stable tag: 1.0.0
     6Stable tag: 2.0
    77
    88==Short Description ==
  • page-specific-sidebars/trunk/Read.ME

    r388109 r509979  
    44Requires at least: 3.0
    55Tested up to: 3.1
    6 Stable tag: 1.0.0
     6Stable tag:  2.0
    77
    88==Short Description ==
  • page-specific-sidebars/trunk/page-sidebar.php

    r394757 r509979  
    44 *  Plugin Name: Simple Page Specific Sidebars
    55 *  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
    77 *  to the existing generic sidebar
    8  *  Version: 1.0.1
     8 *  Version: 2.0
    99 **/
    1010
     
    3232class DGPageSidebarCustom{
    3333   
     34    protected $home_id;
     35    protected $widget_name;
     36   
    3437    public function __construct(){
     38        self::set_opts();
    3539        add_action( 'widgets_init', array( &$this, 'build_sidebars' ) );
    3640        add_action( 'admin_init', array( &$this, 'add_page_meta_box' ) );
    3741        add_action( 'save_post' , array( &$this, 'save_custom_page_meta' ) );
    3842        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';
    4071    }
    4172   
     
    105136    }
    106137     
    107     public function hijack_sidebar( $sidebars ){
     138    public function hijack_sidebar( $sidebars=array() ){
    108139        global $wp_registered_widgets, $wp_registered_sidebars, $_wp_sidebars_widgets, $post;
    109        
     140        $sidebar_title = apply_filters( 'page-sidebar-title' , $this->widget_name );
    110141        if( !is_page() || is_admin() ) return $sidebars;
    111142        $is_custom = get_post_meta( $post->ID, 'is_custom', true );
     
    122153            }else{
    123154                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];
    127157                }else{
    128                    $sidebars['sidebar-1'] = $_wp_sidebars_widgets[$sidebar_term];
     158                   $sidebars[$sidebar_title] = $_wp_sidebars_widgets[$sidebar_term];
    129159                }
    130160                return $sidebars;
     
    133163    }
    134164   
     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     */
    135173    protected function home_pg_id(){
     174        $home_slug = 'home';
    136175        $home_slug = apply_filters( 'page-sidebar-homeslug', $home_slug );
    137176        $pg = get_page_by_path( $home_slug );
  • page-specific-sidebars/trunk/readme.txt

    r394757 r509979  
    44Requires at least: 3.0
    55Tested up to: 3.1
    6 Stable tag: 1.0.0
     6Stable tag: 2.0
    77
    88==Short Description ==
Note: See TracChangeset for help on using the changeset viewer.