WordPress.org

Plugin Directory

Changeset 449734


Ignore:
Timestamp:
10/11/11 05:16:49 (3 years ago)
Author:
alyssonweb
Message:

Added install and uninstall functions. Requires at least 3.0 and Tested up to 3.2.1

Location:
dynamics-sidebars/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • dynamics-sidebars/trunk/ds.class.php

    r445001 r449734  
    1 <?php 
    2 if ( ! defined('ABSPATH') ) 
    3     die(); 
    4  
    5 global $dynamics_sidebars; 
     1<?php if ( ! defined('ABSPATH') ) die(); 
    62 
    73// Check if this class does not already exists 
     
    3228    public function __construct() { 
    3329        // Add some filters 
    34         // add_filter( 'ds_sidebar_name', array( &$this, 'filter_field' ), 1, 1 ); 
    35         // add_filter( 'ds_sidebar_id', array( &$this, 'filter_field' ), 1, 1 ); 
    36         add_filter( 'ds_sidebar_description', array( &$this, 'filter_field' ), 1, 1 ); 
    37         add_filter( 'ds_before_widget', array( &$this, 'filter_field' ), 1, 1 ); 
    38         add_filter( 'ds_after_widget', array( &$this, 'filter_field' ), 1, 1 ); 
    39         add_filter( 'ds_before_title', array( &$this, 'filter_field' ), 1, 1 ); 
    40         add_filter( 'ds_after_title', array( &$this, 'filter_field' ), 1, 1 ); 
     30 
     31        // add_filter( 'ds_sidebar_name', array( &$this, 'filter_field' ), 1 ); 
     32        // add_filter( 'ds_sidebar_id', array( &$this, 'filter_field' ), 1 ); 
     33        add_filter( 'ds_sidebar_description', array( &$this, 'filter_field' ), 1 ); 
     34        add_filter( 'ds_before_widget', array( &$this, 'filter_field' ), 1 ); 
     35        add_filter( 'ds_after_widget', array( &$this, 'filter_field' ), 1 ); 
     36        add_filter( 'ds_before_title', array( &$this, 'filter_field' ), 1 ); 
     37        add_filter( 'ds_after_title', array( &$this, 'filter_field' ), 1 ); 
    4138         
    4239        // Hook our actions 
     
    10198 
    10299            <label for="dynamic_sidebar" style="display: block; margin-bottom: 6px;"><?php _e( 'Dynamic Sidebar Name', 'dynamics_sidebars' ); ?></label> 
    103             <input type="text" id="dynamic_sidebar" name="dynamic_sidebar" value="<?php echo $dynamic_sidebar; ?>" size="40" /> 
     100            <input type="text" id="dynamic_sidebar" name="dynamic_sidebar" value="<?php echo $dynamic_sidebar; ?>" size="33" /> 
    104101 
    105102        <?php 
     
    147144            // Save the data to database 
    148145            update_post_meta( $post_id, 'dynamic_sidebar', $new_data ); 
    149         } elseif ('' == $new && $old) { 
     146        } elseif ('' == $new_data && $old_data) { 
    150147            // Should we delete the old data? 
    151             // delete_post_meta( $post_id, 'dynamic_sidebar', $old_data ); 
     148            delete_post_meta( $post_id, 'dynamic_sidebar', $old_data ); 
    152149        } 
    153150    } 
     
    192189                array( 
    193190                    'name' => $meta_value, // Name and ID should be the same to work with is_active_sidebar function 
    194                     'id' => $this->friendly_string( $meta_value ), // Name and ID should be the same to work with is_active_sidebar function 
     191                    'id' => sanitize_title( $meta_value ), // Name and ID should be the same to work with is_active_sidebar function 
    195192                    'description' => apply_filters( 'ds_sidebar_description', __( $meta_value . ' Widget Area', 'dynamics_sidebars' ) ), 
    196193                    'before_widget' => apply_filters( 'ds_before_widget', '<div id="%1$s" class="widget-container %2$s">' ), 
     
    206203 
    207204    /** 
    208      * Friendly String 
    209      *  
    210      * Convert the passed string to a frindly format for URLs, File Names etc... 
    211      * 
    212      * @access public 
    213      * @param string The string to convert 
    214      * @param int The max number of characters to return 
    215      * @return string New friendly string 
    216      */ 
    217     public function friendly_string( $phrase, $max_length = false ) { 
    218         $phrase = trim( strtolower( esc_html( $phrase ) ) ); 
    219  
    220         if ( empty( $phrase ) ) 
    221             return ''; 
    222          
    223         $new_string = remove_accents( $phrase ); 
    224          
    225         $new_string = trim( preg_replace( "/&{1}(amp;)?/", ' and ', $new_string ) ); 
    226         $new_string = trim( preg_replace( "/[^a-z0-9\s-]/", '', $new_string ) ); 
    227         $new_string = trim( preg_replace( "/[\s-]+/", ' ', $new_string ) ); 
    228          
    229         if ( $max_length ) { 
    230             $max_length = absint( $max_length ); 
    231             $new_string = trim( substr( $result, 0, $max_length ) ); 
    232         } 
    233              
    234         $new_string = preg_replace( "/\s/", "-", $new_string ); 
    235  
    236         return $new_string; 
    237     } 
    238  
    239     /** 
    240205     * Filter Field 
    241206     * 
     
    251216} // End: Dynamics_Sidebars 
    252217 
     218// ------------------------------------------------------------ 
     219 
     220/** 
     221 * Init Dynamics Sidebars 
     222 */ 
     223$ds = new Dynamics_Sidebars; 
     224 
     225// ------------------------------------------------------------ 
     226 
    253227endif; 
    254  
    255 // ------------------------------------------------------------ 
    256  
    257 if ( ! function_exists( 'init_dynamics_sidebars' ) ) : 
    258      
    259     /** 
    260      * Init Dynamics Sidebars 
    261      *  
    262      * Initialize the Dynamics_Sidebars class 
    263      * 
    264      * @return void 
    265      */ 
    266     function init_dynamics_sidebars() { 
    267         global $dynamics_sidebars; 
    268  
    269         $dynamics_sidebars = new Dynamics_Sidebars; 
    270         $dynamics_sidebars = $dynamics_sidebars->get_sidebars(); 
    271     } 
    272  
    273     init_dynamics_sidebars(); 
    274  
    275 endif; 
  • dynamics-sidebars/trunk/dynamics-sidebars.php

    r446976 r449734  
    1 <?php 
    2 if ( ! defined('ABSPATH') ) 
    3     die(); 
     1<?php if ( ! defined('ABSPATH') ) die(); 
     2/** 
     3 * Plugin Name: Dynamics Sidebars 
     4 * Description: Add a custom options to Pages so Pages can display a different sidebars. 
     5 * Author: Alysson Bortoli 
     6 * Author Name: Alysson Bortoli 
     7 * Author URI: http://www.facebook.com/akbortoli | http://twitter.com/#!/akbortoli 
     8 * Version: 0.1.2 
     9 * License: GPLv2 
     10 */ 
     11 
     12if ( ! function_exists( 'ds_install' ) ) : 
    413 
    514/** 
    6  * Plugin Name: Dynamics Sidebars 
    7  * Description: Add a custom options to Pages so they can have different sidebars 
    8  * Author: Tailor Ltd 
    9  * Author URI: http://tailor.co.nz 
    10  * Author Name: Alysson Bortoli 
    11  * Version: 0.1.1 
    12  * License: GPL Compatible 
    13 */ 
     15 * Install 
     16 * 
     17 * Check if the wordpress version is 3.0.0 > if not deactive the plugin 
     18 */ 
     19function ds_install() { 
     20    if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) { 
     21        // Deactivate our plugin 
     22        deactivate_plugins( 'dynamics-sidebars/' . basename( __FILE__ ), true ); 
     23        wp_die( 'Please update to version 3.0 to use this plugin. Your are using wordpress version: ' . get_bloginfo( 'version' ) ); 
     24    } 
     25} 
     26 
     27/** 
     28 * Register the install function 
     29 */ 
     30register_activation_hook( __FILE__, 'ds_install' ); 
     31 
     32endif; 
     33 
     34// ------------------------------------------------------------ 
     35 
     36if ( ! function_exists( 'ds_uninstall' ) ) : 
     37 
     38/** 
     39 * Uninstall 
     40 * 
     41 * Uninstall the Dynamics Sidebars plugin and remove all saved data from Database 
     42 */ 
     43function ds_uninstall() { 
     44    // Get all pages 
     45    $allpages = get_posts('numberposts=-1&post_type=page&post_status=any'); 
     46 
     47    foreach( $allpages as $page ) { 
     48        delete_post_meta( $page->ID, 'dynamic_sidebar' ); 
     49    } 
     50} 
     51 
     52/** 
     53 * Register the uninstall function 
     54 */ 
     55register_deactivation_hook( __FILE__, 'ds_uninstall' ); 
     56 
     57endif; 
    1458 
    1559// include our sidebar file 
  • dynamics-sidebars/trunk/index.php

    r445001 r449734  
    1 <?php 
    2 // Silence is golden. 
    3 ?> 
     1<?php // Silence is golden. ?> 
  • dynamics-sidebars/trunk/readme.txt

    r446974 r449734  
    44Tags: sidebar, widget, dynamic, different 
    55Requires at least: 3.0 
    6 Tested up to: 3.1.2 
    7 Stable tag: 0.1.1 
     6Tested up to: 3.2.1 
     7Stable tag: 0.1.2 
    88 
    9 Add a custom options to Pages so they can have different sidebars 
     9Add a custom field to add widget area for Pages. 
    1010 
    1111== Description == 
    1212 
    13 Add a custom options to Pages so they can have different sidebars widgets areas 
     13Add a custom options to Pages so Pages can display a different sidebars. 
     14 
     15**Please Note** 
     16 
     17* Requires at least: 3.0 
     18* Tested up to: 3.2.1 
     19 
     20**Install** 
     21 
     221. Unzip the dynamics-sidebars.zip file. 
     231. 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. 
     24 
     25**Activate** 
     26 
     271. In your WordPress administration, go to the Plugins page 
     281. Activate the Dynamics Sidebars plugin. 
     29 
     30**Usage** 
     31 
     321. After activating the plugin 
     331. Go to the Pages > Add or New and you should see the Dynamic Sidebar Metabox on the side (if not showing up try active 'Dynamic Sidebar' under 'Screen Options' on 'Edit Page' page on the top-right handside and make sure 'Dynamic Sidebar' is ticked ) 
     341. Enter the name of your dynamic sidebar, recommend to put the same name as your page title 
     351. Go to the Appearance > Widget page and place anything on your new widget area 
     361. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 
     37 
     38`<?php 
     39    // Get the current post sidebar area 
     40    $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
     41     
     42    // Display the sidebar area 
     43    dynamic_sidebar( $dynamic_sidebar ); 
     44?>` 
     45 
     46**Checking if sidebar is active** 
     47`<?php 
     48    // Get the current post sidebar area 
     49    $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
     50 
     51    if ( is_active_sidebar( $dynamic_sidebar ) ) { 
     52        // Do your stuff 
     53    } 
     54?>` 
     55 
     56**Changing before_widget and after_widget** 
     57 
     58On your functions.php file just add the following code, don't forget to change 'function_to_return_my_new_*' to your own function 
     59`<?php 
     60    add_filter( 'ds_sidebar_description', 'function_to_return_my_new_sidebar_description' ); 
     61    add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
     62    add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
     63    add_filter( 'ds_before_title', 'function_to_return_my_new_before_title' ); 
     64    add_filter( 'ds_after_title', 'function_to_return_my_new_after_title' ); 
     65?>` 
     66 
     67***Here is an example:*** 
     68 
     69`<?php 
     70    add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
     71    add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
     72 
     73    function ds_before_widget(){ 
     74        return '<div id="%1$s" class="widget-container %2$s">'; 
     75    } 
     76 
     77    function ds_after_widget(){ 
     78        return '</div>'; 
     79    } 
     80?>` 
    1481 
    1582== Installation == 
    1683 
    17 Install 
     84**Install** 
    1885 
    19861. Unzip the dynamics-sidebars.zip file. 
     871. 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. 
    2088 
    21 2. 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. 
    22  
    23 Activate 
     89**Activate** 
    2490 
    25911. In your WordPress administration, go to the Plugins page 
     921. Activate the Dynamics Sidebars plugin. 
    2693 
    27 2. Activate the Dynamics Sidebars plugin. 
     94**Usage** 
    2895 
    29 3. Go to the Pages > Add or New and you should see the Dynamic Sidebar Metabox on the side 
     961. After activating the plugin 
     971. Go to the Pages > Add or New and you should see the Dynamic Sidebar Metabox on the side (if not showing up try active 'Dynamic Sidebar' under 'Screen Options' on 'Edit Page' page on the top-right handside and make sure 'Dynamic Sidebar' is ticked ) 
     981. Enter the name of your dynamic sidebar, recommend to put the same name as your page title 
     991. Go to the Appearance > Widget page and place anything on your new widget area 
     1001. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 
    30101 
    31 4. Enter the name of your dynamic sidebar, recomment to put the same name as you page name 
     102`<?php 
     103    // Get the current post sidebar area 
     104    $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
     105     
     106    // Display the sidebar area 
     107    dynamic_sidebar( $dynamic_sidebar ); 
     108?>` 
    32109 
    33 5. Go to the Appearance > Widget page and place anything on your new widget area 
     110**Checking if sidebar is active** 
     111`<?php 
     112    // Get the current post sidebar area 
     113    $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
    34114 
    35 6. On your template page.php or custom template just add the following code 
     115    if ( is_active_sidebar( $dynamic_sidebar ) ) { 
     116        // Do your stuff 
     117    } 
     118?>` 
    36119 
     120**Changing before_widget and after_widget** 
    37121 
    38     <?php 
    39         $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
    40         dynamic_sidebar( $dynamic_sidebar );  
    41     ?> 
     122On your functions.php file just add the following code, don't forget to change 'function_to_return_my_new_*' to your own function 
     123`<?php 
     124    add_filter( 'ds_sidebar_description', 'function_to_return_my_new_sidebar_description' ); 
     125    add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
     126    add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
     127    add_filter( 'ds_before_title', 'function_to_return_my_new_before_title' ); 
     128    add_filter( 'ds_after_title', 'function_to_return_my_new_after_title' ); 
     129?>` 
     130 
     131***Here is an example:*** 
     132 
     133`<?php 
     134    add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
     135    add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
     136 
     137    function ds_before_widget(){ 
     138        return '<div id="%1$s" class="widget-container %2$s">'; 
     139    } 
     140 
     141    function ds_after_widget(){ 
     142        return '</div>'; 
     143    } 
     144?>` 
    42145 
    43146= 0.1 = 
    44  
    45147* First version of the plugin. 
    46148 
    47149= 0.1.1 = 
     150* Changes to the readme.txt 
    48151 
    49 * Changes to the readme.txt 
     152= 0.1.2 = 
     153* Added install and uninstall functions 
     154* Checked version 3.0 > 3.2.1 
     155* Changes to 'readme.txt' 
     156* Requires at least: 3.0 
     157* Tested up to: 3.2.1 
    50158 
    51159== Upgrade Notice == 
    52160 
    53161= 0.1 = 
    54  
    55162First version of the plugin. Stable version. 
    56163 
    57164= 0.1.1 = 
     165Minor changes and change to 'readme.txt' 
    58166 
    59 Changes to "readme.txt" 
     167= 0.1.2 = 
     168Added install and uninstall functions and others minor changes 
Note: See TracChangeset for help on using the changeset viewer.