WordPress.org

Plugin Directory

Changeset 571073


Ignore:
Timestamp:
07/12/12 05:37:25 (22 months ago)
Author:
alyssonweb
Message:

Version 1.0.1

Location:
dynamics-sidebars
Files:
6 added
2 deleted
12 edited
5 copied

Legend:

Unmodified
Added
Removed
  • dynamics-sidebars/tags/1.0.1/css/style.css

    r570487 r571073  
    1 #postbox-container-1 #dynamic-sidebar-select, 
    2 #postbox-container-1 #dynamic-sidebar-text { 
    3     width: auto; 
    4     max-width: 70%; 
    5 } 
    6  
    7 #postbox-container-2 #dynamic-sidebar-select, 
    8 #postbox-container-2 #dynamic-sidebar-text { 
    9     width: auto; 
    10     max-width: 85%; 
    11 } 
    12  
    13 #dynamic-sidebar-select, 
    14 #dynamic-sidebar-text { 
    15     display: inline-block; 
    16     margin-bottom: 7px; 
    17     padding: 3px 3px 4px; 
    18 } 
    19  
    20 #dynamic-sidebar-error, 
    21 #dynamic-sidebar-message { 
    22     margin: 7px 0 7px; 
    23     padding: 0 .6em; 
    24     border-radius: 3px; 
    25     border-width: 1px; 
    26     border-style: solid; 
    27 } 
    28  
    29 #dynamic-sidebar-message { 
    30     background-color: #FFFFE0; 
    31     border-color: #E6DB55; 
    32 } 
    33  
    34 #dynamic-sidebar-error { 
    35     background-color: #FFEBE8; 
    36     border-color: #C00; 
    37 } 
    38      
    39     #dynamic-sidebar-error p, 
    40     #dynamic-sidebar-message p { 
    41         color: #333; 
    42         margin: .5em 0; 
    43         padding: 2px; 
    44     } 
    45  
    46 #dynamic-sidebar-add, 
    47 #dynamic-sidebar-cancel { 
    48     display: inline-block; 
    49 } 
     1#postbox-container-1 #dynamic-sidebar-select, #postbox-container-1 #dynamic-sidebar-text { width: auto; max-width: 70%; } 
     2#postbox-container-2 #dynamic-sidebar-select, #postbox-container-2 #dynamic-sidebar-text { width: auto; max-width: 85%; } 
     3#dynamic-sidebar-select, #dynamic-sidebar-text { display: inline-block; margin-bottom: 7px; padding: 3px 3px 4px; } 
     4#dynamic-sidebar-error, #dynamic-sidebar-message { margin: 7px 0 7px; padding: 0 .6em; border-radius: 3px; border-width: 1px; border-style: solid; } 
     5#dynamic-sidebar-message { background-color: #FFFFE0; border-color: #E6DB55; } 
     6#dynamic-sidebar-error { background-color: #FFEBE8; border-color: #C00; } 
     7#dynamic-sidebar-error p, #dynamic-sidebar-message p { color: #333; margin: .5em 0; padding: 2px; } 
     8#dynamic-sidebar-add, #dynamic-sidebar-cancel { display: inline-block; } 
  • dynamics-sidebars/tags/1.0.1/dynamics-sidebars.php

    r570487 r571073  
    77 * Author Name: Alysson Bortoli 
    88 * Author URI: http://twitter.com/akbortoli 
    9  * Version: 1.0.0 
     9 * Version: 1.0.1 
    1010 * License: GPLv2 or later 
    1111 */ 
    1212 
     13/*  Copyright 2012  Alysson Bortoli  (email : alysson.web@gmail.com) 
     14 
     15    This program is free software; you can redistribute it and/or modify 
     16    it under the terms of the GNU General Public License, version 2, as  
     17    published by the Free Software Foundation. 
     18 
     19    This program is distributed in the hope that it will be useful, 
     20    but WITHOUT ANY WARRANTY; without even the implied warranty of 
     21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     22    GNU General Public License for more details. 
     23 
     24    You should have received a copy of the GNU General Public License 
     25    along with this program; if not, write to the Free Software 
     26    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     27*/ 
     28 
    1329// ------------------------------------------------------------ 
    14  
    15 // should render for posts 
    16 if ( ! defined( 'DS_PLUGIN_FOR_PAGES' ) ) 
    17     define( 'DS_PLUGIN_FOR_PAGES', true ); 
    18  
    19 // should render for posts 
    20 if ( ! defined( 'DS_PLUGIN_FOR_POSTS' ) ) 
    21     define( 'DS_PLUGIN_FOR_POSTS', true ); 
    2230 
    2331// should render on page on front 
     
    3745// ------------------------------------------------------------ 
    3846 
    39 if ( ! function_exists( 'ds_plugin_install' ) ) : 
    40  
    41 /** 
    42  * Install 
    43  * 
    44  * Check if the wordpress version is 3.0.0 > if not deactive the plugin 
    45  */ 
    46 function ds_plugin_install() 
    47 { 
    48     if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) { 
    49         // Deactivate plugin 
    50         deactivate_plugins( 'dynamics-sidebars/' . basename( __FILE__ ), true ); 
    51         wp_die( sprintf( __( 'Please update you Wordpress version to at least 3.0 to use this plugin. Your are using wordpress version: %s' ), get_bloginfo( 'version' ) ) ); 
    52     } 
    53  
    54     do_action( 'ds_plugin_install' ); 
    55 } 
    56  
    57 register_activation_hook( __FILE__, 'ds_plugin_install' ); 
    58  
    59 endif; 
     47include_once( 'includes/api.php' ); 
     48include_once( 'includes/class-dynamic-sidebars.php' ); 
    6049 
    6150// ------------------------------------------------------------ 
    6251 
    63 if ( ! function_exists( 'ds_plugin_uninstall' ) ) : 
    64  
    65 /** 
    66  * Uninstall 
    67  * 
    68  * Uninstall the Dynamics Sidebars plugin and remove all saved data from Database 
    69  */ 
    70 function ds_plugin_uninstall() 
    71 { 
    72     global $wpdb; 
    73  
    74     // Delete custom fields 'dynamic_sidebar' 
    75     $query = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s", DS_PLUGIN_CUSTOM_FIELD ); 
    76     $wpdb->query( $query ); 
    77  
    78     do_action( 'ds_plugin_uninstall' ); 
    79 } 
    80  
    81 register_deactivation_hook( __FILE__, 'ds_plugin_uninstall' ); 
    82  
    83 endif; 
    84  
    85 // ------------------------------------------------------------ 
    86  
    87 include_once( 'includes/api.php' ); 
    88 include_once( 'includes/class-dynamic-sidebars.php' ); 
     52$dynamic_sidebars_class = Dynamic_Sidebars::get_instance(); 
  • dynamics-sidebars/tags/1.0.1/includes/api.php

    r570487 r571073  
    1 <?php 
     1<?php if ( ! defined( 'ABSPATH' ) ) wp_die(); 
     2 
     3/** 
     4 * Dynamics Sidebars 
     5 * Api Functions 
     6 * 
     7 */ 
    28 
    39if ( ! function_exists( 'the_sidebar' ) ) : 
     
    4248    $page_on_front  = absint( get_option( 'page_on_front' ) ); 
    4349    $page_for_posts = absint( get_option( 'page_for_posts' ) ); 
    44  
    45     if ( 'page' == $post->post_type && ! DS_PLUGIN_FOR_PAGES ) { 
    46         return apply_filters( 'the_sidebar', '', $post_id ); 
    47     } elseif ( 'post' == $post->post_type && ! DS_PLUGIN_FOR_POSTS ) { 
     50     
     51    if ( ! post_type_supports( $post->post_type, 'custom-sidebar' ) ) { 
    4852        return apply_filters( 'the_sidebar', '', $post_id ); 
    4953    } elseif ( ! DS_PLUGIN_FOR_FRONT_PAGE && $page_on_front == $post->ID ) { 
     
    5559        return apply_filters( 'the_sidebar', $sidebar, $post_id ); 
    5660    } 
     61} 
     62 
     63endif; 
     64 
     65// ------------------------------------------------------------ 
     66 
     67if ( ! function_exists( 'has_sidebar' ) ) : 
     68 
     69/** 
     70 * Check if post has a sidebar.. 
     71 * 
     72 * @uses get_the_sidebar() 
     73 * @param int $post_id (Optional) Post ID. 
     74 * @return bool 
     75 */ 
     76function has_sidebar( $post_id = 0 ) 
     77{ 
     78    $sidebar = get_the_sidebar( $post_id ); 
     79    if ( ! $sidebar || empty( $sidebar ) ) { 
     80        return false; 
     81    } 
     82 
     83    return true; 
    5784} 
    5885 
  • dynamics-sidebars/tags/1.0.1/includes/class-dynamic-sidebars.php

    r570487 r571073  
    33if ( ! class_exists( 'Dynamic_Sidebars' ) ) : 
    44 
     5/** 
     6 * Dynamic Sidebars Object 
     7 * 
     8 * @package WordPress 
     9 * @subpackage Dynamic_Sidebars 
     10 */ 
    511class Dynamic_Sidebars 
    612{ 
    713    /** 
     14     * Instance 
     15     *  
     16     * @access private 
     17     * @var object 
     18     */ 
     19    private static $instance; 
     20 
     21    // ------------------------------------------------------------ 
     22     
     23    /** 
     24     * Class Name 
     25     *  
     26     * @access private 
     27     * @var string 
     28     */ 
     29    private static $class = 'Dynamic_Sidebars'; 
     30 
     31    // ------------------------------------------------------------ 
     32     
     33    /** 
     34     * Plugin Path 
     35     *  
     36     * @access private 
     37     * @return string 
     38     */ 
     39    private static $plugin_path; 
     40 
     41    // ------------------------------------------------------------ 
     42 
     43    /** 
    844     * Constructor 
    945     *  
     
    1147     * @return void 
    1248     */ 
    13     public function __construct() 
    14     { 
     49    private function __construct() 
     50    { 
     51        // plugin path 
     52        self::$plugin_path = realpath( dirname( __FILE__ ) . '/../dynamics-sidebars.php' ); 
     53 
     54        // load text domain 
    1555        load_plugin_textdomain( DS_PLUGIN_I18N_DOMAIN, null, str_replace( 'includes', 'languages', dirname( plugin_basename( __FILE__ ) ) ) ); 
    1656 
     57        // install hook 
     58        register_activation_hook( self::$plugin_path, array( &$this, 'plugin_install' ) ); 
     59 
     60        // deactive hook 
     61        register_deactivation_hook( self::$plugin_path, array( &$this, 'plugin_deactivate' ) ); 
     62         
     63        // Add post feature if not added yet 
     64        if ( post_type_exists( 'post' ) && ! post_type_supports( 'post', 'custom-sidebar' ) ) 
     65            add_post_type_support( 'post', 'custom-sidebar' ); 
     66 
     67        // Add page feature if not added yet 
     68        if ( post_type_exists( 'page' ) && ! post_type_supports( 'page', 'custom-sidebar' ) ) 
     69            add_post_type_support( 'page', 'custom-sidebar' ); 
     70 
     71        if ( is_admin() ) { 
     72            // Hook up actions 
     73            // add_action( 'init', array( &$this, 'init' ), 0 ); 
     74            add_action( 'init', array( &$this, 'register_column' ), 100 ); 
     75            add_action( 'init', array( &$this, 'register_sidebars' ), 11 ); 
     76            add_action( 'add_meta_boxes', array( &$this, 'add_metabox' ), 12 ); 
     77            add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_script_style' ) ); 
     78            add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit_custom_box' ), 10, 2 ); 
     79            add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit_custom_box' ), 10, 2 ); 
     80            add_action( 'wp_ajax_ds_save_post', array( &$this, 'save_ajax' ) ); 
     81            add_action( 'wp_ajax_ds_update_select', array( &$this, 'update_select' ) ); 
     82            add_action( 'save_post', array( &$this, 'save' ) ); 
     83        } 
     84 
     85        // hook 
     86        do_action( 'ds_construct', &$this ); 
     87    } 
     88 
     89    // ------------------------------------------------------------ 
     90 
     91    /** 
     92     * Get Instance (Singleton) 
     93     *  
     94     * @access public 
     95     * @return object 
     96     */ 
     97    public function get_instance() 
     98    { 
     99        if ( empty( self::$instance ) ) { 
     100            self::$instance = new self::$class; 
     101        } 
     102        return self::$instance; 
     103    } 
     104 
     105    // ------------------------------------------------------------ 
     106 
     107    /** 
     108     * Install 
     109     * 
     110     * Check if the wordpress version is 3.0.0 > if not deactive the plugin 
     111     *  
     112     * @access public 
     113     * @return bool 
     114     */ 
     115    public function plugin_install() 
     116    { 
     117        if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) { 
     118            // Deactivate plugin 
     119            deactivate_plugins( 'dynamics-sidebars/dynamics-sidebars.php', true ); 
     120            wp_die( sprintf( __( 'Please update you Wordpress version to at least 3.0 to use this plugin. Your are using wordpress version: %s' ), get_bloginfo( 'version' ) ) ); 
     121        } 
     122 
     123        // hook 
     124        do_action( 'ds_plugin_install' ); 
     125        return true; 
     126    } 
     127 
     128    // ------------------------------------------------------------ 
     129 
     130    /** 
     131     * Deactivate 
     132     * 
     133     * Deactivate the Dynamics Sidebars plugin 
     134     * Should delete all data? 
     135     *  
     136     * @access public 
     137     * @return bool 
     138     */ 
     139    public function plugin_deactivate() 
     140    { 
     141        // hook 
     142        do_action( 'ds_plugin_deactivate' ); 
     143        return true; 
     144    } 
     145 
     146    // ------------------------------------------------------------ 
     147 
     148    /** 
     149     * Register Column 
     150     * 
     151     * @access public 
     152     * @return void 
     153     */ 
     154    public function register_column() 
     155    { 
    17156        // Check if in the admin area 
    18157        if ( is_admin() ) { 
    19             // Hook up actions 
    20             add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_script_style' ) ); 
    21             add_action( 'init', array( &$this, 'register_sidebars' ), 11 ); 
    22  
    23             add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit_custom_box' ), 10, 2 ); 
    24             add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit_custom_box' ), 10, 2 ); 
    25  
    26             // Hook up filters 
    27             if ( DS_PLUGIN_FOR_POSTS ) { 
    28                 add_filter( 'manage_post_posts_columns', array( &$this, 'manage_posts_columns' ) ); 
    29                 add_action('manage_posts_custom_column', array( &$this, 'render_post_columns' ), 10, 2); 
     158            // Get all post types 
     159            $post_types = apply_filters( 'ds_post_types', get_post_types() ); 
     160 
     161            foreach ( $post_types as $post_type ) { 
     162                if ( post_type_supports( $post_type, 'custom-sidebar' ) ) { 
     163                    add_filter( "manage_{$post_type}_posts_columns", array( &$this, 'manage_posts_columns' ) ); 
     164 
     165                    if ( 'page' == $post_type ) 
     166                        add_action( 'manage_pages_custom_column', array( &$this, 'render_post_columns' ), 10, 2 ); 
     167                    else 
     168                        add_action( 'manage_posts_custom_column', array( &$this, 'render_post_columns' ), 10, 2 ); 
     169                } 
    30170            } 
    31              
    32             if ( DS_PLUGIN_FOR_PAGES ) { 
    33                 add_filter( 'manage_page_posts_columns', array( &$this, 'manage_posts_columns' ) ); 
    34                 add_action('manage_pages_custom_column', array( &$this, 'render_post_columns' ), 10, 2); 
     171 
     172            do_action( 'ds_register_column' ); 
     173        } 
     174    } 
     175 
     176    // ------------------------------------------------------------ 
     177 
     178    /** 
     179     * Add Metabox 
     180     *  
     181     * Add the dynamic sidebar metabox 
     182     * 
     183     * @access public 
     184     * @return void 
     185     */ 
     186    public function add_metabox() 
     187    { 
     188        global $post_id; 
     189 
     190        // Get all post types 
     191        $post_types = apply_filters( 'ds_post_types', get_post_types() ); 
     192 
     193        $page_on_front  = absint( get_option( 'page_on_front' ) ); 
     194        $page_for_posts = absint( get_option( 'page_for_posts' ) ); 
     195 
     196        foreach ( $post_types as $post_type ) { 
     197            if ( 'page' == $post_type ) { 
     198                if ( ! DS_PLUGIN_FOR_POSTS_PAGE && $page_for_posts == $post_id ) 
     199                    continue; 
     200                elseif ( ! DS_PLUGIN_FOR_FRONT_PAGE && $page_on_front == $post_id ) 
     201                    continue; 
    35202            } 
    36203 
    37             add_action( 'add_meta_boxes', array( &$this, 'add_metabox' ), 12 ); 
    38             add_action( 'save_post', array( &$this, 'save' ) ); 
    39             add_action( 'wp_ajax_ds_save_post', array( &$this, 'save_ajax' ) ); 
    40             add_action( 'wp_ajax_ds_update_select', array( &$this, 'update_select' ) ); 
    41  
    42             do_action( 'ds_construct', &$this ); 
    43         } 
    44     } 
    45  
    46     // ------------------------------------------------------------ 
    47  
    48     /** 
    49      * Add Metabox 
    50      *  
    51      * Add the dynamic sidebar metabox 
    52      * 
    53      * @access public 
    54      * @return void 
    55      */ 
    56     public function add_metabox() 
    57     { 
    58         global $post_id; 
    59  
    60         // page on front 
    61         $page_on_front  = absint( get_option( 'page_on_front' ) ); 
    62  
    63         // page for posts 
    64         $page_for_posts = absint( get_option( 'page_for_posts' ) ); 
    65  
    66         // pages 
    67         if ( DS_PLUGIN_FOR_PAGES ) 
    68             add_meta_box( 'dynamic-sidebar-metabox', __( 'Sidebar', DS_PLUGIN_I18N_DOMAIN ), array( &$this, 'render_metabox' ), 'page', 'side', 'default' ); 
    69  
    70         // remove for "page_on_front" 
    71         if ( DS_PLUGIN_FOR_PAGES && ! DS_PLUGIN_FOR_FRONT_PAGE && $page_on_front == $post_id ) 
    72             remove_meta_box( 'dynamic-sidebar-metabox', 'page', 'side' ); 
    73  
    74         // remove for "page_for_posts" 
    75         if ( DS_PLUGIN_FOR_PAGES && ! DS_PLUGIN_FOR_POSTS_PAGE && $page_for_posts == $post_id ) 
    76             remove_meta_box( 'dynamic-sidebar-metabox', 'page', 'side' ); 
    77          
    78         // posts 
    79         if ( DS_PLUGIN_FOR_POSTS ) 
    80             add_meta_box( 'dynamic-sidebar-metabox', __( 'Sidebar', DS_PLUGIN_I18N_DOMAIN ), array( &$this, 'render_metabox' ), 'post', 'side', 'default' ); 
    81  
    82         do_action( 'ds_add_metabox' ); 
     204            if ( post_type_supports( $post_type, 'custom-sidebar' ) ) { 
     205                add_meta_box( 'dynamic-sidebar-metabox', __( 'Sidebar', DS_PLUGIN_I18N_DOMAIN ), array( &$this, 'render_metabox' ), $post_type, 'side', 'default' ); 
     206            } 
     207        } 
     208 
     209        // hook 
     210        do_action( 'ds_add_metabox', $post_type ); 
    83211    } 
    84212 
     
    96224    public function render_metabox() 
    97225    { 
    98         global $post_id, $wp_registered_sidebars, $wp_scripts; 
    99  
    100         $selected = get_post_meta( $post_id, 'dynamic_sidebar', true ); 
     226        global $post_id, $wp_registered_sidebars; 
     227 
     228        if ( ! $post_id ) 
     229            return; 
     230 
     231        $selected = get_the_sidebar( $post_id ); 
    101232        $total_sidebars = count( $wp_registered_sidebars ); 
    102233    ?> 
     
    105236            <div id="dynamic-sidebar-error" style="display:none;"></div> 
    106237            <select id="dynamic-sidebar-select" name="<?php echo DS_PLUGIN_CUSTOM_FIELD; ?>_select"> 
    107                  
     238                <option value=""><?php echo esc_html( __( '&mdash; None &mdash;', DS_PLUGIN_I18N_DOMAIN ) ); ?></option> 
    108239                <?php foreach ( $wp_registered_sidebars as $s ) : ?> 
    109240                    <option value="<?php echo esc_attr( $s[ 'name' ] ); ?>" <?php selected( $selected, $s[ 'name' ] ); ?>><?php echo $s[ 'name' ]; ?></option> 
     
    117248        </div> 
    118249    <?php 
     250        // hook 
    119251        do_action( 'ds_render_metabox' ); 
    120252    } 
     
    175307        $this->save_sidebar( $post_id ); 
    176308 
     309        // hook 
    177310        do_action( 'ds_save', $post_id, $post ); 
    178311 
     
    273406        $post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0; 
    274407 
    275         $selected = get_post_meta( $post_id, 'dynamic_sidebar', true ); 
     408        $selected = get_sidebar( $post_id ); 
    276409        $total_sidebars = count( $wp_registered_sidebars ); 
    277410    ?> 
     
    301434            return false; 
    302435         
    303         $old = get_post_meta( $post_id, DS_PLUGIN_CUSTOM_FIELD, true ); 
     436        $old = get_the_sidebar( $post_id ); 
    304437 
    305438        if ( ! isset( $_REQUEST['bulk_edit'] ) ) { 
     
    415548 
    416549        // script 
    417         wp_enqueue_script( 'ds-plugin-script', plugins_url( 'dynamics-sidebars/js/script.js', 'dynamics-sidebars' ), array( 'jquery' ), null, true ); 
     550        wp_enqueue_script( 'ds-plugin-script', plugins_url( 'dynamics-sidebars/js/script.min.js', 'dynamics-sidebars' ), array( 'jquery' ), null, true ); 
    418551        wp_localize_script( 'ds-plugin-script', '_ds', array( 
    419552                'ajaxurl' => admin_url( 'admin-ajax.php' ), 
     
    461594        switch ( $column_name ) { 
    462595            case 'dynamic_sidebar': 
    463                 $sidebar = get_post_meta( $post_id, 'dynamic_sidebar', true ); 
     596                $sidebar = get_the_sidebar( $post_id, 'dynamic_sidebar', true ); 
    464597                if ( $sidebar ) 
    465598                    echo '<a href="' . admin_url( '/widgets.php' ) . '">' . esc_html( $sidebar ) . '</a>'; 
     
    526659            return; 
    527660 
    528         $selected = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
     661        $selected = get_the_sidebar( $post->ID ); 
    529662        $total_sidebars = count( $wp_registered_sidebars ); 
    530663    ?> 
     
    549682} 
    550683 
    551 // ------------------------------------------------------------ 
    552  
    553 $ds = new Dynamic_Sidebars(); 
    554  
    555684endif; 
  • dynamics-sidebars/tags/1.0.1/readme.txt

    r570494 r571073  
    55Requires at least: 3.0 
    66Tested up to: 3.4.1 
    7 Stable tag: 1.0.0 
     7Stable tag: 1.0.1 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    10 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=J3AJV4ZZ4WKYQ&lc=NZ&item_name=WordPress%20Dynamics%20Sidebars&currency_code=NZD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted 
    11  
    12 Create a custom widget area (sidebar) for pages, posts and custom post types. 
     10Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6NTZTQUPXP8F2 
     11 
     12Create a custom (dynamic) widget area (sidebar) to pages, posts and custom post types. 
    1313 
    1414 
    1515== Description == 
    1616 
    17 **Please Note** 
    18  
    19 * Requires at least wp version: 3.0 
    20  
    21  
    22 **Install** 
    23  
    24 1. Unzip the dynamics-sidebars.zip file. 
    25 1. Upload the the dynamics-sidebars folder (not just the files in it!) to your wp-contents/plugins folder. If you're using FTP, use 'binary' mode. 
    26  
    27  
    28 **Activate** 
    29  
    30 1. In your WordPress administration, go to the Plugins page 
    31 1. Activate the Dynamics Sidebars plugin. 
    32  
     17Want your pages/posts or custom post types to have differents sidebar areas? This plugin is for you! 
     18 
     19An awesome plugin to add custom (dynamic) widget area (sidebar) to your page, post or even custom post type. 
    3320 
    3421**Usage** 
    3522 
    36 1. After activating the plugin 
    37 1. Go to the Pages/Posts/CTP > Add new or Edit and you should see the "Sidebar" metabox on the side (if not showing up try active "Sidebar" under 'Screen Options' on the top-right handside and make sure "Sidebar" is ticked ) 
    38 1. Enter the name for your sidebar area (recommend to use same as your page title) 
    39 1. Go to the Appearance > Widgets and place anything onto your new widget area 
    40 1. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 
    41  
    4223`<?php 
    4324    dynamic_sidebar( get_the_sidebar() ); 
    4425?>` 
    4526 
    46  
    47 **Checking if sidebar is active** 
     27Or 
    4828 
    4929`<?php 
     
    5434?>` 
    5535 
    56 **Check the new API** 
    57  
    58 `<?php 
    59     // get the current page/post/cpt sidebar with fallback (sidebar id or name) if needed, set ECHO to true to echo out the sidebar name 
    60     // the_sidebar( $fallback = '', $echo = false ) 
    61  
    62     // get current page/post/cpt sidebar, $post_id is optional 
    63     // get_the_sidebar( $post_id = 0 ) 
    64  
    65     // get all custom sidebars (custom only) 
    66     // get_custom_sidebars() 
    67  
    68     // get all registered sidebars 
    69     // get_all_sidebars() 
    70 ?>` 
    71  
    72 And many filters and actions to hook on to. 
    73  
    74  
    75 **Changing before_widget and after_widget** 
    76  
    77 On your functions.php file just add the following code. (don't forget to change 'function to return my sidebar items' to your own function name 
    78 `<?php 
    79     add_filter( 'ds_sidebar_args', 'function to return my sidebar items' ); 
    80 ?>` 
    81  
    82 ***Here is an example:*** 
    83  
     36**Changing sidebar args** 
     37 
     38On your 'functions.php' file just add the following code. 
    8439 
    8540`<?php 
     
    9954?>` 
    10055 
     56**Remove from poge/post or custom post type** 
     57 
     58`<?php 
     59    remove_post_type_support( 'post', 'custom-sidebar' ); // to remove from posts 
     60    remove_post_type_support( 'page', 'custom-sidebar' ); // to remove from pages 
     61    remove_post_type_support( 'custom post type', 'custom-sidebar' ); // to remove from ctp 
     62?>` 
     63 
     64**Don't forget to check the 'Other Notes' tab for a list of all function and hook you can use.** 
     65 
    10166 
    10267== Installation == 
     
    10570 
    10671* Requires at least: 3.0 
     72* Tested up to: 3.4.1 
    10773 
    10874 
     
    11581**Activate** 
    11682 
    117 1. In your WordPress administration, go to the Plugins page 
    118 1. Activate the Dynamics Sidebars plugin. 
     831. In your WordPress admin area, go to "Plugins" page 
     841. Activate the "Dynamics Sidebars" plugin. 
    11985 
    12086 
     
    125913. Bulk Edit 
    12692 
     93 
    12794== Frequently Asked Questions == 
    12895 
    12996No FAQ yet. 
    13097 
     98 
    13199== Changelog == 
    132100 
     101= 1.0.1 = 
     102 
     103* Api: has_sidebar() 
     104* Action: ds_init 
     105* Action: ds_plugin_deactivate 
     106* Action: ds_register_column 
     107* Filter: ds_post_types 
     108* Added register_post_type pass to 'supports' => array( 'custom-sidebar' ) 
     109* API: has_sidebar( $post_id = 0 ) 
     110* Support for add_post_type_support (add post type feature) 
     111* Support for remove_post_type_support (remove post type feature) 
     112* Support for post_type_supports (check if post type supports feature) 
     113* Support for get_all_post_type_supports (get all features for a post type) 
     114* REMOVED Constant: DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
     115* REMOVED Constant: DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
     116 
    133117= 1.0.0 = 
    134118 
    135 * Added bulk edit 
    136 * Added quick edit 
    137 * Added select box with all registered sidebars and a text input for registering a new one 
    138 * Added save via ajax 
    139 * Added save via publich/update/save draft 
    140 * Added API: 
     119* Added: bulk edit 
     120* Added: quick edit 
     121* Added: select box with all registered sidebars and a text input for registering a new one 
     122* Added: save via ajax 
     123* Added: save via publich/update/save draft 
     124* Added: .POT file for Internationalization (i18n) 
     125* Added: pt_BR Translation 
     126* Api: the_sidebar( $fallback = '', $echo = false ) 
     127* Api: get_the_sidebar( $post_id = 0 ) 
     128* Api: get_custom_sidebars() 
     129* Api: get_all_sidebars() 
     130* Filter: the_sidebar 
     131* Filter: ds_save_permissions 
     132* Filter: ds_save_ajax_message 
     133* Filter: ds_save_ajax 
     134* Filter: ds_sidebar_args 
     135* Action: ds_plugin_install 
     136* Action: ds_plugin_uninstall 
     137* Action: ds_construct 
     138* Action: ds_add_metabox 
     139* Action: ds_render_metabox 
     140* Action: ds_save 
     141* Constant: DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
     142* Constant: DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
     143* Constant: DS_PLUGIN_FOR_FRONT_PAGE, to render or not "Sidebar" metabox for front page "page_on_front" (if set) 
     144* Constant: DS_PLUGIN_FOR_POSTS_PAGE, to render or not "Sidebar" metabox for posts page "page_for_posts" (if set) 
     145 
     146= 0.1.2 = 
     147 
     148* Added install and uninstall functions 
     149* Changes to 'readme.txt' 
     150* Requires at least: 3.0 
     151* Tested up to: 3.4.1 
     152 
     153= 0.1 = 
     154 
     155* First release. 
     156 
     157== Upgrade Notice == 
     158 
     159Fixed deactivation hook deleting all data and added some other features. 
     160 
     161 
     162== Internationalization (i18n) == 
     163 
     164This plugin has been translated into the languages listed below: 
     165 
     166* pt_BR - Portuguese Brazil. 
     167 
     168If you're interested in doing a translation into your language, please let me know. 
     169 
     170== Api == 
     171 
     172**Functions** 
     173 
     174* has_sidebar( $post_id = 0 ) 
    141175* the_sidebar( $fallback = '', $echo = false ) 
    142176* get_the_sidebar( $post_id = 0 ) 
    143177* get_custom_sidebars() 
    144178* get_all_sidebars() 
    145 * Added FILTERS: 
     179 
     180 
     181**Actions** 
     182 
     183* ds_plugin_install 
     184* ds_plugin_uninstall 
     185* ds_plugin_deactivate 
     186* ds_construct 
     187* ds_add_metabox 
     188* ds_render_metabox 
     189* ds_save 
     190* ds_init 
     191* ds_register_column 
     192 
     193 
     194**Filters** 
     195 
    146196* the_sidebar 
    147197* ds_save_permissions 
     
    149199* ds_save_ajax 
    150200* ds_sidebar_args 
    151 * Added ACTIONS 
    152 * ds_plugin_install 
    153 * ds_plugin_uninstall 
    154 * ds_construct 
    155 * ds_add_metabox 
    156 * ds_render_metabox 
    157 * ds_save 
    158 * Added CONSTANTS 
    159 * DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
    160 * DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
    161 * DS_PLUGIN_FOR_FRONT_PAGE, to render or not "Sidebar" metabox for front page "page_on_front" (if set) 
    162 * DS_PLUGIN_FOR_POSTS_PAGE, to render or not "Sidebar" metabox for posts page "page_for_posts" (if set) 
    163 * Added .POT file for Internationalization (i18n) 
    164  
    165 = 0.1.2 = 
    166  
    167 * Added install and uninstall functions 
    168 * Changes to 'readme.txt' 
    169 * Requires at least: 3.0 
    170 * Tested up to: 3.4.1 
    171  
    172 = 0.1 = 
    173  
    174 * First release. 
    175  
    176 == Upgrade Notice == 
    177  
    178 = 1.0.0 = 
    179  
    180 * Added bulk edit 
    181 * Added quick edit 
    182 * Added select box with all registered sidebars and a text input for registering a new one 
    183 * Added save via ajax 
    184 * Added save via publich/update/save draft 
    185 * Added API: 
    186 * the_sidebar( $fallback = '', $echo = false ) 
    187 * get_the_sidebar( $post_id = 0 ) 
    188 * get_custom_sidebars() 
    189 * get_all_sidebars() 
    190 * Added FILTERS: 
    191 * the_sidebar 
    192 * ds_save_permissions 
    193 * ds_save_ajax_message 
    194 * ds_save_ajax 
    195 * ds_sidebar_args 
    196 * Added ACTIONS 
    197 * ds_plugin_install 
    198 * ds_plugin_uninstall 
    199 * ds_construct 
    200 * ds_add_metabox 
    201 * ds_render_metabox 
    202 * ds_save 
    203 * Added CONSTANTS 
    204 * DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
    205 * DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
    206 * DS_PLUGIN_FOR_FRONT_PAGE, to render or not "Sidebar" metabox for front page "page_on_front" (if set) 
    207 * DS_PLUGIN_FOR_POSTS_PAGE, to render or not "Sidebar" metabox for posts page "page_for_posts" (if set) 
    208 * Added .POT file for Internationalization (i18n) 
    209  
    210 = 0.1.2 = 
    211  
    212 * Added install and uninstall functions 
    213 * Changes to 'readme.txt' 
    214 * Requires at least: 3.0 
    215 * Tested up to: 3.4.1 
    216  
    217 = 0.1 = 
    218  
    219 * First release. 
    220  
    221 == Internationalization (i18n) == 
    222  
    223 This plugin has been translated into the languages listed below: 
    224  
    225 * pt_BR - Portuguese Brazil. 
    226  
    227 If you're interested in doing a translation into your language, please let me know. 
     201* ds_post_types 
     202 
     203 
     204**Constant** 
     205 
     206* DS_PLUGIN_FOR_FRONT_PAGE 
     207* DS_PLUGIN_FOR_POSTS_PAGE 
  • dynamics-sidebars/tags/1.0.1/uninstall.php

    r570487 r571073  
    11<?php 
    22 
    3 //if uninstall not called from WordPress exit 
     3// if uninstall not called from WordPress exit 
    44if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) 
    55    wp_die(); 
  • dynamics-sidebars/trunk/css/style.css

    r570487 r571073  
    1 #postbox-container-1 #dynamic-sidebar-select, 
    2 #postbox-container-1 #dynamic-sidebar-text { 
    3     width: auto; 
    4     max-width: 70%; 
    5 } 
    6  
    7 #postbox-container-2 #dynamic-sidebar-select, 
    8 #postbox-container-2 #dynamic-sidebar-text { 
    9     width: auto; 
    10     max-width: 85%; 
    11 } 
    12  
    13 #dynamic-sidebar-select, 
    14 #dynamic-sidebar-text { 
    15     display: inline-block; 
    16     margin-bottom: 7px; 
    17     padding: 3px 3px 4px; 
    18 } 
    19  
    20 #dynamic-sidebar-error, 
    21 #dynamic-sidebar-message { 
    22     margin: 7px 0 7px; 
    23     padding: 0 .6em; 
    24     border-radius: 3px; 
    25     border-width: 1px; 
    26     border-style: solid; 
    27 } 
    28  
    29 #dynamic-sidebar-message { 
    30     background-color: #FFFFE0; 
    31     border-color: #E6DB55; 
    32 } 
    33  
    34 #dynamic-sidebar-error { 
    35     background-color: #FFEBE8; 
    36     border-color: #C00; 
    37 } 
    38      
    39     #dynamic-sidebar-error p, 
    40     #dynamic-sidebar-message p { 
    41         color: #333; 
    42         margin: .5em 0; 
    43         padding: 2px; 
    44     } 
    45  
    46 #dynamic-sidebar-add, 
    47 #dynamic-sidebar-cancel { 
    48     display: inline-block; 
    49 } 
     1#postbox-container-1 #dynamic-sidebar-select, #postbox-container-1 #dynamic-sidebar-text { width: auto; max-width: 70%; } 
     2#postbox-container-2 #dynamic-sidebar-select, #postbox-container-2 #dynamic-sidebar-text { width: auto; max-width: 85%; } 
     3#dynamic-sidebar-select, #dynamic-sidebar-text { display: inline-block; margin-bottom: 7px; padding: 3px 3px 4px; } 
     4#dynamic-sidebar-error, #dynamic-sidebar-message { margin: 7px 0 7px; padding: 0 .6em; border-radius: 3px; border-width: 1px; border-style: solid; } 
     5#dynamic-sidebar-message { background-color: #FFFFE0; border-color: #E6DB55; } 
     6#dynamic-sidebar-error { background-color: #FFEBE8; border-color: #C00; } 
     7#dynamic-sidebar-error p, #dynamic-sidebar-message p { color: #333; margin: .5em 0; padding: 2px; } 
     8#dynamic-sidebar-add, #dynamic-sidebar-cancel { display: inline-block; } 
  • dynamics-sidebars/trunk/dynamics-sidebars.php

    r570487 r571073  
    77 * Author Name: Alysson Bortoli 
    88 * Author URI: http://twitter.com/akbortoli 
    9  * Version: 1.0.0 
     9 * Version: 1.0.1 
    1010 * License: GPLv2 or later 
    1111 */ 
    1212 
     13/*  Copyright 2012  Alysson Bortoli  (email : alysson.web@gmail.com) 
     14 
     15    This program is free software; you can redistribute it and/or modify 
     16    it under the terms of the GNU General Public License, version 2, as  
     17    published by the Free Software Foundation. 
     18 
     19    This program is distributed in the hope that it will be useful, 
     20    but WITHOUT ANY WARRANTY; without even the implied warranty of 
     21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     22    GNU General Public License for more details. 
     23 
     24    You should have received a copy of the GNU General Public License 
     25    along with this program; if not, write to the Free Software 
     26    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     27*/ 
     28 
    1329// ------------------------------------------------------------ 
    14  
    15 // should render for posts 
    16 if ( ! defined( 'DS_PLUGIN_FOR_PAGES' ) ) 
    17     define( 'DS_PLUGIN_FOR_PAGES', true ); 
    18  
    19 // should render for posts 
    20 if ( ! defined( 'DS_PLUGIN_FOR_POSTS' ) ) 
    21     define( 'DS_PLUGIN_FOR_POSTS', true ); 
    2230 
    2331// should render on page on front 
     
    3745// ------------------------------------------------------------ 
    3846 
    39 if ( ! function_exists( 'ds_plugin_install' ) ) : 
    40  
    41 /** 
    42  * Install 
    43  * 
    44  * Check if the wordpress version is 3.0.0 > if not deactive the plugin 
    45  */ 
    46 function ds_plugin_install() 
    47 { 
    48     if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) { 
    49         // Deactivate plugin 
    50         deactivate_plugins( 'dynamics-sidebars/' . basename( __FILE__ ), true ); 
    51         wp_die( sprintf( __( 'Please update you Wordpress version to at least 3.0 to use this plugin. Your are using wordpress version: %s' ), get_bloginfo( 'version' ) ) ); 
    52     } 
    53  
    54     do_action( 'ds_plugin_install' ); 
    55 } 
    56  
    57 register_activation_hook( __FILE__, 'ds_plugin_install' ); 
    58  
    59 endif; 
     47include_once( 'includes/api.php' ); 
     48include_once( 'includes/class-dynamic-sidebars.php' ); 
    6049 
    6150// ------------------------------------------------------------ 
    6251 
    63 if ( ! function_exists( 'ds_plugin_uninstall' ) ) : 
    64  
    65 /** 
    66  * Uninstall 
    67  * 
    68  * Uninstall the Dynamics Sidebars plugin and remove all saved data from Database 
    69  */ 
    70 function ds_plugin_uninstall() 
    71 { 
    72     global $wpdb; 
    73  
    74     // Delete custom fields 'dynamic_sidebar' 
    75     $query = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s", DS_PLUGIN_CUSTOM_FIELD ); 
    76     $wpdb->query( $query ); 
    77  
    78     do_action( 'ds_plugin_uninstall' ); 
    79 } 
    80  
    81 register_deactivation_hook( __FILE__, 'ds_plugin_uninstall' ); 
    82  
    83 endif; 
    84  
    85 // ------------------------------------------------------------ 
    86  
    87 include_once( 'includes/api.php' ); 
    88 include_once( 'includes/class-dynamic-sidebars.php' ); 
     52$dynamic_sidebars_class = Dynamic_Sidebars::get_instance(); 
  • dynamics-sidebars/trunk/includes/api.php

    r570487 r571073  
    1 <?php 
     1<?php if ( ! defined( 'ABSPATH' ) ) wp_die(); 
     2 
     3/** 
     4 * Dynamics Sidebars 
     5 * Api Functions 
     6 * 
     7 */ 
    28 
    39if ( ! function_exists( 'the_sidebar' ) ) : 
     
    4248    $page_on_front  = absint( get_option( 'page_on_front' ) ); 
    4349    $page_for_posts = absint( get_option( 'page_for_posts' ) ); 
    44  
    45     if ( 'page' == $post->post_type && ! DS_PLUGIN_FOR_PAGES ) { 
    46         return apply_filters( 'the_sidebar', '', $post_id ); 
    47     } elseif ( 'post' == $post->post_type && ! DS_PLUGIN_FOR_POSTS ) { 
     50     
     51    if ( ! post_type_supports( $post->post_type, 'custom-sidebar' ) ) { 
    4852        return apply_filters( 'the_sidebar', '', $post_id ); 
    4953    } elseif ( ! DS_PLUGIN_FOR_FRONT_PAGE && $page_on_front == $post->ID ) { 
     
    5559        return apply_filters( 'the_sidebar', $sidebar, $post_id ); 
    5660    } 
     61} 
     62 
     63endif; 
     64 
     65// ------------------------------------------------------------ 
     66 
     67if ( ! function_exists( 'has_sidebar' ) ) : 
     68 
     69/** 
     70 * Check if post has a sidebar.. 
     71 * 
     72 * @uses get_the_sidebar() 
     73 * @param int $post_id (Optional) Post ID. 
     74 * @return bool 
     75 */ 
     76function has_sidebar( $post_id = 0 ) 
     77{ 
     78    $sidebar = get_the_sidebar( $post_id ); 
     79    if ( ! $sidebar || empty( $sidebar ) ) { 
     80        return false; 
     81    } 
     82 
     83    return true; 
    5784} 
    5885 
  • dynamics-sidebars/trunk/includes/class-dynamic-sidebars.php

    r570487 r571073  
    33if ( ! class_exists( 'Dynamic_Sidebars' ) ) : 
    44 
     5/** 
     6 * Dynamic Sidebars Object 
     7 * 
     8 * @package WordPress 
     9 * @subpackage Dynamic_Sidebars 
     10 */ 
    511class Dynamic_Sidebars 
    612{ 
    713    /** 
     14     * Instance 
     15     *  
     16     * @access private 
     17     * @var object 
     18     */ 
     19    private static $instance; 
     20 
     21    // ------------------------------------------------------------ 
     22     
     23    /** 
     24     * Class Name 
     25     *  
     26     * @access private 
     27     * @var string 
     28     */ 
     29    private static $class = 'Dynamic_Sidebars'; 
     30 
     31    // ------------------------------------------------------------ 
     32     
     33    /** 
     34     * Plugin Path 
     35     *  
     36     * @access private 
     37     * @return string 
     38     */ 
     39    private static $plugin_path; 
     40 
     41    // ------------------------------------------------------------ 
     42 
     43    /** 
    844     * Constructor 
    945     *  
     
    1147     * @return void 
    1248     */ 
    13     public function __construct() 
    14     { 
     49    private function __construct() 
     50    { 
     51        // plugin path 
     52        self::$plugin_path = realpath( dirname( __FILE__ ) . '/../dynamics-sidebars.php' ); 
     53 
     54        // load text domain 
    1555        load_plugin_textdomain( DS_PLUGIN_I18N_DOMAIN, null, str_replace( 'includes', 'languages', dirname( plugin_basename( __FILE__ ) ) ) ); 
    1656 
     57        // install hook 
     58        register_activation_hook( self::$plugin_path, array( &$this, 'plugin_install' ) ); 
     59 
     60        // deactive hook 
     61        register_deactivation_hook( self::$plugin_path, array( &$this, 'plugin_deactivate' ) ); 
     62         
     63        // Add post feature if not added yet 
     64        if ( post_type_exists( 'post' ) && ! post_type_supports( 'post', 'custom-sidebar' ) ) 
     65            add_post_type_support( 'post', 'custom-sidebar' ); 
     66 
     67        // Add page feature if not added yet 
     68        if ( post_type_exists( 'page' ) && ! post_type_supports( 'page', 'custom-sidebar' ) ) 
     69            add_post_type_support( 'page', 'custom-sidebar' ); 
     70 
     71        if ( is_admin() ) { 
     72            // Hook up actions 
     73            // add_action( 'init', array( &$this, 'init' ), 0 ); 
     74            add_action( 'init', array( &$this, 'register_column' ), 100 ); 
     75            add_action( 'init', array( &$this, 'register_sidebars' ), 11 ); 
     76            add_action( 'add_meta_boxes', array( &$this, 'add_metabox' ), 12 ); 
     77            add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_script_style' ) ); 
     78            add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit_custom_box' ), 10, 2 ); 
     79            add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit_custom_box' ), 10, 2 ); 
     80            add_action( 'wp_ajax_ds_save_post', array( &$this, 'save_ajax' ) ); 
     81            add_action( 'wp_ajax_ds_update_select', array( &$this, 'update_select' ) ); 
     82            add_action( 'save_post', array( &$this, 'save' ) ); 
     83        } 
     84 
     85        // hook 
     86        do_action( 'ds_construct', &$this ); 
     87    } 
     88 
     89    // ------------------------------------------------------------ 
     90 
     91    /** 
     92     * Get Instance (Singleton) 
     93     *  
     94     * @access public 
     95     * @return object 
     96     */ 
     97    public function get_instance() 
     98    { 
     99        if ( empty( self::$instance ) ) { 
     100            self::$instance = new self::$class; 
     101        } 
     102        return self::$instance; 
     103    } 
     104 
     105    // ------------------------------------------------------------ 
     106 
     107    /** 
     108     * Install 
     109     * 
     110     * Check if the wordpress version is 3.0.0 > if not deactive the plugin 
     111     *  
     112     * @access public 
     113     * @return bool 
     114     */ 
     115    public function plugin_install() 
     116    { 
     117        if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) { 
     118            // Deactivate plugin 
     119            deactivate_plugins( 'dynamics-sidebars/dynamics-sidebars.php', true ); 
     120            wp_die( sprintf( __( 'Please update you Wordpress version to at least 3.0 to use this plugin. Your are using wordpress version: %s' ), get_bloginfo( 'version' ) ) ); 
     121        } 
     122 
     123        // hook 
     124        do_action( 'ds_plugin_install' ); 
     125        return true; 
     126    } 
     127 
     128    // ------------------------------------------------------------ 
     129 
     130    /** 
     131     * Deactivate 
     132     * 
     133     * Deactivate the Dynamics Sidebars plugin 
     134     * Should delete all data? 
     135     *  
     136     * @access public 
     137     * @return bool 
     138     */ 
     139    public function plugin_deactivate() 
     140    { 
     141        // hook 
     142        do_action( 'ds_plugin_deactivate' ); 
     143        return true; 
     144    } 
     145 
     146    // ------------------------------------------------------------ 
     147 
     148    /** 
     149     * Register Column 
     150     * 
     151     * @access public 
     152     * @return void 
     153     */ 
     154    public function register_column() 
     155    { 
    17156        // Check if in the admin area 
    18157        if ( is_admin() ) { 
    19             // Hook up actions 
    20             add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_script_style' ) ); 
    21             add_action( 'init', array( &$this, 'register_sidebars' ), 11 ); 
    22  
    23             add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit_custom_box' ), 10, 2 ); 
    24             add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit_custom_box' ), 10, 2 ); 
    25  
    26             // Hook up filters 
    27             if ( DS_PLUGIN_FOR_POSTS ) { 
    28                 add_filter( 'manage_post_posts_columns', array( &$this, 'manage_posts_columns' ) ); 
    29                 add_action('manage_posts_custom_column', array( &$this, 'render_post_columns' ), 10, 2); 
     158            // Get all post types 
     159            $post_types = apply_filters( 'ds_post_types', get_post_types() ); 
     160 
     161            foreach ( $post_types as $post_type ) { 
     162                if ( post_type_supports( $post_type, 'custom-sidebar' ) ) { 
     163                    add_filter( "manage_{$post_type}_posts_columns", array( &$this, 'manage_posts_columns' ) ); 
     164 
     165                    if ( 'page' == $post_type ) 
     166                        add_action( 'manage_pages_custom_column', array( &$this, 'render_post_columns' ), 10, 2 ); 
     167                    else 
     168                        add_action( 'manage_posts_custom_column', array( &$this, 'render_post_columns' ), 10, 2 ); 
     169                } 
    30170            } 
    31              
    32             if ( DS_PLUGIN_FOR_PAGES ) { 
    33                 add_filter( 'manage_page_posts_columns', array( &$this, 'manage_posts_columns' ) ); 
    34                 add_action('manage_pages_custom_column', array( &$this, 'render_post_columns' ), 10, 2); 
     171 
     172            do_action( 'ds_register_column' ); 
     173        } 
     174    } 
     175 
     176    // ------------------------------------------------------------ 
     177 
     178    /** 
     179     * Add Metabox 
     180     *  
     181     * Add the dynamic sidebar metabox 
     182     * 
     183     * @access public 
     184     * @return void 
     185     */ 
     186    public function add_metabox() 
     187    { 
     188        global $post_id; 
     189 
     190        // Get all post types 
     191        $post_types = apply_filters( 'ds_post_types', get_post_types() ); 
     192 
     193        $page_on_front  = absint( get_option( 'page_on_front' ) ); 
     194        $page_for_posts = absint( get_option( 'page_for_posts' ) ); 
     195 
     196        foreach ( $post_types as $post_type ) { 
     197            if ( 'page' == $post_type ) { 
     198                if ( ! DS_PLUGIN_FOR_POSTS_PAGE && $page_for_posts == $post_id ) 
     199                    continue; 
     200                elseif ( ! DS_PLUGIN_FOR_FRONT_PAGE && $page_on_front == $post_id ) 
     201                    continue; 
    35202            } 
    36203 
    37             add_action( 'add_meta_boxes', array( &$this, 'add_metabox' ), 12 ); 
    38             add_action( 'save_post', array( &$this, 'save' ) ); 
    39             add_action( 'wp_ajax_ds_save_post', array( &$this, 'save_ajax' ) ); 
    40             add_action( 'wp_ajax_ds_update_select', array( &$this, 'update_select' ) ); 
    41  
    42             do_action( 'ds_construct', &$this ); 
    43         } 
    44     } 
    45  
    46     // ------------------------------------------------------------ 
    47  
    48     /** 
    49      * Add Metabox 
    50      *  
    51      * Add the dynamic sidebar metabox 
    52      * 
    53      * @access public 
    54      * @return void 
    55      */ 
    56     public function add_metabox() 
    57     { 
    58         global $post_id; 
    59  
    60         // page on front 
    61         $page_on_front  = absint( get_option( 'page_on_front' ) ); 
    62  
    63         // page for posts 
    64         $page_for_posts = absint( get_option( 'page_for_posts' ) ); 
    65  
    66         // pages 
    67         if ( DS_PLUGIN_FOR_PAGES ) 
    68             add_meta_box( 'dynamic-sidebar-metabox', __( 'Sidebar', DS_PLUGIN_I18N_DOMAIN ), array( &$this, 'render_metabox' ), 'page', 'side', 'default' ); 
    69  
    70         // remove for "page_on_front" 
    71         if ( DS_PLUGIN_FOR_PAGES && ! DS_PLUGIN_FOR_FRONT_PAGE && $page_on_front == $post_id ) 
    72             remove_meta_box( 'dynamic-sidebar-metabox', 'page', 'side' ); 
    73  
    74         // remove for "page_for_posts" 
    75         if ( DS_PLUGIN_FOR_PAGES && ! DS_PLUGIN_FOR_POSTS_PAGE && $page_for_posts == $post_id ) 
    76             remove_meta_box( 'dynamic-sidebar-metabox', 'page', 'side' ); 
    77          
    78         // posts 
    79         if ( DS_PLUGIN_FOR_POSTS ) 
    80             add_meta_box( 'dynamic-sidebar-metabox', __( 'Sidebar', DS_PLUGIN_I18N_DOMAIN ), array( &$this, 'render_metabox' ), 'post', 'side', 'default' ); 
    81  
    82         do_action( 'ds_add_metabox' ); 
     204            if ( post_type_supports( $post_type, 'custom-sidebar' ) ) { 
     205                add_meta_box( 'dynamic-sidebar-metabox', __( 'Sidebar', DS_PLUGIN_I18N_DOMAIN ), array( &$this, 'render_metabox' ), $post_type, 'side', 'default' ); 
     206            } 
     207        } 
     208 
     209        // hook 
     210        do_action( 'ds_add_metabox', $post_type ); 
    83211    } 
    84212 
     
    96224    public function render_metabox() 
    97225    { 
    98         global $post_id, $wp_registered_sidebars, $wp_scripts; 
    99  
    100         $selected = get_post_meta( $post_id, 'dynamic_sidebar', true ); 
     226        global $post_id, $wp_registered_sidebars; 
     227 
     228        if ( ! $post_id ) 
     229            return; 
     230 
     231        $selected = get_the_sidebar( $post_id ); 
    101232        $total_sidebars = count( $wp_registered_sidebars ); 
    102233    ?> 
     
    105236            <div id="dynamic-sidebar-error" style="display:none;"></div> 
    106237            <select id="dynamic-sidebar-select" name="<?php echo DS_PLUGIN_CUSTOM_FIELD; ?>_select"> 
    107                  
     238                <option value=""><?php echo esc_html( __( '&mdash; None &mdash;', DS_PLUGIN_I18N_DOMAIN ) ); ?></option> 
    108239                <?php foreach ( $wp_registered_sidebars as $s ) : ?> 
    109240                    <option value="<?php echo esc_attr( $s[ 'name' ] ); ?>" <?php selected( $selected, $s[ 'name' ] ); ?>><?php echo $s[ 'name' ]; ?></option> 
     
    117248        </div> 
    118249    <?php 
     250        // hook 
    119251        do_action( 'ds_render_metabox' ); 
    120252    } 
     
    175307        $this->save_sidebar( $post_id ); 
    176308 
     309        // hook 
    177310        do_action( 'ds_save', $post_id, $post ); 
    178311 
     
    273406        $post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0; 
    274407 
    275         $selected = get_post_meta( $post_id, 'dynamic_sidebar', true ); 
     408        $selected = get_sidebar( $post_id ); 
    276409        $total_sidebars = count( $wp_registered_sidebars ); 
    277410    ?> 
     
    301434            return false; 
    302435         
    303         $old = get_post_meta( $post_id, DS_PLUGIN_CUSTOM_FIELD, true ); 
     436        $old = get_the_sidebar( $post_id ); 
    304437 
    305438        if ( ! isset( $_REQUEST['bulk_edit'] ) ) { 
     
    415548 
    416549        // script 
    417         wp_enqueue_script( 'ds-plugin-script', plugins_url( 'dynamics-sidebars/js/script.js', 'dynamics-sidebars' ), array( 'jquery' ), null, true ); 
     550        wp_enqueue_script( 'ds-plugin-script', plugins_url( 'dynamics-sidebars/js/script.min.js', 'dynamics-sidebars' ), array( 'jquery' ), null, true ); 
    418551        wp_localize_script( 'ds-plugin-script', '_ds', array( 
    419552                'ajaxurl' => admin_url( 'admin-ajax.php' ), 
     
    461594        switch ( $column_name ) { 
    462595            case 'dynamic_sidebar': 
    463                 $sidebar = get_post_meta( $post_id, 'dynamic_sidebar', true ); 
     596                $sidebar = get_the_sidebar( $post_id, 'dynamic_sidebar', true ); 
    464597                if ( $sidebar ) 
    465598                    echo '<a href="' . admin_url( '/widgets.php' ) . '">' . esc_html( $sidebar ) . '</a>'; 
     
    526659            return; 
    527660 
    528         $selected = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
     661        $selected = get_the_sidebar( $post->ID ); 
    529662        $total_sidebars = count( $wp_registered_sidebars ); 
    530663    ?> 
     
    549682} 
    550683 
    551 // ------------------------------------------------------------ 
    552  
    553 $ds = new Dynamic_Sidebars(); 
    554  
    555684endif; 
  • dynamics-sidebars/trunk/readme.txt

    r570494 r571073  
    55Requires at least: 3.0 
    66Tested up to: 3.4.1 
    7 Stable tag: 1.0.0 
     7Stable tag: 1.0.1 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    10 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=J3AJV4ZZ4WKYQ&lc=NZ&item_name=WordPress%20Dynamics%20Sidebars&currency_code=NZD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted 
    11  
    12 Create a custom widget area (sidebar) for pages, posts and custom post types. 
     10Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6NTZTQUPXP8F2 
     11 
     12Create a custom (dynamic) widget area (sidebar) to pages, posts and custom post types. 
    1313 
    1414 
    1515== Description == 
    1616 
    17 **Please Note** 
    18  
    19 * Requires at least wp version: 3.0 
    20  
    21  
    22 **Install** 
    23  
    24 1. Unzip the dynamics-sidebars.zip file. 
    25 1. Upload the the dynamics-sidebars folder (not just the files in it!) to your wp-contents/plugins folder. If you're using FTP, use 'binary' mode. 
    26  
    27  
    28 **Activate** 
    29  
    30 1. In your WordPress administration, go to the Plugins page 
    31 1. Activate the Dynamics Sidebars plugin. 
    32  
     17Want your pages/posts or custom post types to have differents sidebar areas? This plugin is for you! 
     18 
     19An awesome plugin to add custom (dynamic) widget area (sidebar) to your page, post or even custom post type. 
    3320 
    3421**Usage** 
    3522 
    36 1. After activating the plugin 
    37 1. Go to the Pages/Posts/CTP > Add new or Edit and you should see the "Sidebar" metabox on the side (if not showing up try active "Sidebar" under 'Screen Options' on the top-right handside and make sure "Sidebar" is ticked ) 
    38 1. Enter the name for your sidebar area (recommend to use same as your page title) 
    39 1. Go to the Appearance > Widgets and place anything onto your new widget area 
    40 1. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 
    41  
    4223`<?php 
    4324    dynamic_sidebar( get_the_sidebar() ); 
    4425?>` 
    4526 
    46  
    47 **Checking if sidebar is active** 
     27Or 
    4828 
    4929`<?php 
     
    5434?>` 
    5535 
    56 **Check the new API** 
    57  
    58 `<?php 
    59     // get the current page/post/cpt sidebar with fallback (sidebar id or name) if needed, set ECHO to true to echo out the sidebar name 
    60     // the_sidebar( $fallback = '', $echo = false ) 
    61  
    62     // get current page/post/cpt sidebar, $post_id is optional 
    63     // get_the_sidebar( $post_id = 0 ) 
    64  
    65     // get all custom sidebars (custom only) 
    66     // get_custom_sidebars() 
    67  
    68     // get all registered sidebars 
    69     // get_all_sidebars() 
    70 ?>` 
    71  
    72 And many filters and actions to hook on to. 
    73  
    74  
    75 **Changing before_widget and after_widget** 
    76  
    77 On your functions.php file just add the following code. (don't forget to change 'function to return my sidebar items' to your own function name 
    78 `<?php 
    79     add_filter( 'ds_sidebar_args', 'function to return my sidebar items' ); 
    80 ?>` 
    81  
    82 ***Here is an example:*** 
    83  
     36**Changing sidebar args** 
     37 
     38On your 'functions.php' file just add the following code. 
    8439 
    8540`<?php 
     
    9954?>` 
    10055 
     56**Remove from poge/post or custom post type** 
     57 
     58`<?php 
     59    remove_post_type_support( 'post', 'custom-sidebar' ); // to remove from posts 
     60    remove_post_type_support( 'page', 'custom-sidebar' ); // to remove from pages 
     61    remove_post_type_support( 'custom post type', 'custom-sidebar' ); // to remove from ctp 
     62?>` 
     63 
     64**Don't forget to check the 'Other Notes' tab for a list of all function and hook you can use.** 
     65 
    10166 
    10267== Installation == 
     
    10570 
    10671* Requires at least: 3.0 
     72* Tested up to: 3.4.1 
    10773 
    10874 
     
    11581**Activate** 
    11682 
    117 1. In your WordPress administration, go to the Plugins page 
    118 1. Activate the Dynamics Sidebars plugin. 
     831. In your WordPress admin area, go to "Plugins" page 
     841. Activate the "Dynamics Sidebars" plugin. 
    11985 
    12086 
     
    125913. Bulk Edit 
    12692 
     93 
    12794== Frequently Asked Questions == 
    12895 
    12996No FAQ yet. 
    13097 
     98 
    13199== Changelog == 
    132100 
     101= 1.0.1 = 
     102 
     103* Api: has_sidebar() 
     104* Action: ds_init 
     105* Action: ds_plugin_deactivate 
     106* Action: ds_register_column 
     107* Filter: ds_post_types 
     108* Added register_post_type pass to 'supports' => array( 'custom-sidebar' ) 
     109* API: has_sidebar( $post_id = 0 ) 
     110* Support for add_post_type_support (add post type feature) 
     111* Support for remove_post_type_support (remove post type feature) 
     112* Support for post_type_supports (check if post type supports feature) 
     113* Support for get_all_post_type_supports (get all features for a post type) 
     114* REMOVED Constant: DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
     115* REMOVED Constant: DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
     116 
    133117= 1.0.0 = 
    134118 
    135 * Added bulk edit 
    136 * Added quick edit 
    137 * Added select box with all registered sidebars and a text input for registering a new one 
    138 * Added save via ajax 
    139 * Added save via publich/update/save draft 
    140 * Added API: 
     119* Added: bulk edit 
     120* Added: quick edit 
     121* Added: select box with all registered sidebars and a text input for registering a new one 
     122* Added: save via ajax 
     123* Added: save via publich/update/save draft 
     124* Added: .POT file for Internationalization (i18n) 
     125* Added: pt_BR Translation 
     126* Api: the_sidebar( $fallback = '', $echo = false ) 
     127* Api: get_the_sidebar( $post_id = 0 ) 
     128* Api: get_custom_sidebars() 
     129* Api: get_all_sidebars() 
     130* Filter: the_sidebar 
     131* Filter: ds_save_permissions 
     132* Filter: ds_save_ajax_message 
     133* Filter: ds_save_ajax 
     134* Filter: ds_sidebar_args 
     135* Action: ds_plugin_install 
     136* Action: ds_plugin_uninstall 
     137* Action: ds_construct 
     138* Action: ds_add_metabox 
     139* Action: ds_render_metabox 
     140* Action: ds_save 
     141* Constant: DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
     142* Constant: DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
     143* Constant: DS_PLUGIN_FOR_FRONT_PAGE, to render or not "Sidebar" metabox for front page "page_on_front" (if set) 
     144* Constant: DS_PLUGIN_FOR_POSTS_PAGE, to render or not "Sidebar" metabox for posts page "page_for_posts" (if set) 
     145 
     146= 0.1.2 = 
     147 
     148* Added install and uninstall functions 
     149* Changes to 'readme.txt' 
     150* Requires at least: 3.0 
     151* Tested up to: 3.4.1 
     152 
     153= 0.1 = 
     154 
     155* First release. 
     156 
     157== Upgrade Notice == 
     158 
     159Fixed deactivation hook deleting all data and added some other features. 
     160 
     161 
     162== Internationalization (i18n) == 
     163 
     164This plugin has been translated into the languages listed below: 
     165 
     166* pt_BR - Portuguese Brazil. 
     167 
     168If you're interested in doing a translation into your language, please let me know. 
     169 
     170== Api == 
     171 
     172**Functions** 
     173 
     174* has_sidebar( $post_id = 0 ) 
    141175* the_sidebar( $fallback = '', $echo = false ) 
    142176* get_the_sidebar( $post_id = 0 ) 
    143177* get_custom_sidebars() 
    144178* get_all_sidebars() 
    145 * Added FILTERS: 
     179 
     180 
     181**Actions** 
     182 
     183* ds_plugin_install 
     184* ds_plugin_uninstall 
     185* ds_plugin_deactivate 
     186* ds_construct 
     187* ds_add_metabox 
     188* ds_render_metabox 
     189* ds_save 
     190* ds_init 
     191* ds_register_column 
     192 
     193 
     194**Filters** 
     195 
    146196* the_sidebar 
    147197* ds_save_permissions 
     
    149199* ds_save_ajax 
    150200* ds_sidebar_args 
    151 * Added ACTIONS 
    152 * ds_plugin_install 
    153 * ds_plugin_uninstall 
    154 * ds_construct 
    155 * ds_add_metabox 
    156 * ds_render_metabox 
    157 * ds_save 
    158 * Added CONSTANTS 
    159 * DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
    160 * DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
    161 * DS_PLUGIN_FOR_FRONT_PAGE, to render or not "Sidebar" metabox for front page "page_on_front" (if set) 
    162 * DS_PLUGIN_FOR_POSTS_PAGE, to render or not "Sidebar" metabox for posts page "page_for_posts" (if set) 
    163 * Added .POT file for Internationalization (i18n) 
    164  
    165 = 0.1.2 = 
    166  
    167 * Added install and uninstall functions 
    168 * Changes to 'readme.txt' 
    169 * Requires at least: 3.0 
    170 * Tested up to: 3.4.1 
    171  
    172 = 0.1 = 
    173  
    174 * First release. 
    175  
    176 == Upgrade Notice == 
    177  
    178 = 1.0.0 = 
    179  
    180 * Added bulk edit 
    181 * Added quick edit 
    182 * Added select box with all registered sidebars and a text input for registering a new one 
    183 * Added save via ajax 
    184 * Added save via publich/update/save draft 
    185 * Added API: 
    186 * the_sidebar( $fallback = '', $echo = false ) 
    187 * get_the_sidebar( $post_id = 0 ) 
    188 * get_custom_sidebars() 
    189 * get_all_sidebars() 
    190 * Added FILTERS: 
    191 * the_sidebar 
    192 * ds_save_permissions 
    193 * ds_save_ajax_message 
    194 * ds_save_ajax 
    195 * ds_sidebar_args 
    196 * Added ACTIONS 
    197 * ds_plugin_install 
    198 * ds_plugin_uninstall 
    199 * ds_construct 
    200 * ds_add_metabox 
    201 * ds_render_metabox 
    202 * ds_save 
    203 * Added CONSTANTS 
    204 * DS_PLUGIN_FOR_PAGES, to render or not "Sidebar" metabox for pages 
    205 * DS_PLUGIN_FOR_POSTS, to render or not "Sidebar" metabox for posts 
    206 * DS_PLUGIN_FOR_FRONT_PAGE, to render or not "Sidebar" metabox for front page "page_on_front" (if set) 
    207 * DS_PLUGIN_FOR_POSTS_PAGE, to render or not "Sidebar" metabox for posts page "page_for_posts" (if set) 
    208 * Added .POT file for Internationalization (i18n) 
    209  
    210 = 0.1.2 = 
    211  
    212 * Added install and uninstall functions 
    213 * Changes to 'readme.txt' 
    214 * Requires at least: 3.0 
    215 * Tested up to: 3.4.1 
    216  
    217 = 0.1 = 
    218  
    219 * First release. 
    220  
    221 == Internationalization (i18n) == 
    222  
    223 This plugin has been translated into the languages listed below: 
    224  
    225 * pt_BR - Portuguese Brazil. 
    226  
    227 If you're interested in doing a translation into your language, please let me know. 
     201* ds_post_types 
     202 
     203 
     204**Constant** 
     205 
     206* DS_PLUGIN_FOR_FRONT_PAGE 
     207* DS_PLUGIN_FOR_POSTS_PAGE 
  • dynamics-sidebars/trunk/uninstall.php

    r570487 r571073  
    11<?php 
    22 
    3 //if uninstall not called from WordPress exit 
     3// if uninstall not called from WordPress exit 
    44if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) 
    55    wp_die(); 
Note: See TracChangeset for help on using the changeset viewer.