WordPress.org

Plugin Directory

Changeset 570487


Ignore:
Timestamp:
07/11/12 07:04:28 (22 months ago)
Author:
alyssonweb
Message:

Version 1.0.0

Location:
dynamics-sidebars/trunk
Files:
17 added
1 deleted
2 edited

Legend:

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

    r449741 r570487  
    1 <?php if ( ! defined('ABSPATH') ) die(); 
     1<?php if ( ! defined( 'ABSPATH' ) ) die(); 
     2 
    23/** 
    34 * Plugin Name: Dynamics Sidebars 
    4  * Description: Add a custom options to Pages so Pages can display a different sidebars. 
     5 * Description: Create a custom widget area (sidebar) for pages, posts and custom post types. 
    56 * Author: Alysson Bortoli 
    67 * Author Name: Alysson Bortoli 
    7  * Author URI: http://twitter.com/#!/akbortoli 
    8  * Version: 0.1.3 
    9  * License: GPLv2 
     8 * Author URI: http://twitter.com/akbortoli 
     9 * Version: 1.0.0 
     10 * License: GPLv2 or later 
    1011 */ 
    1112 
    12 if ( ! function_exists( 'ds_install' ) ) : 
     13// ------------------------------------------------------------ 
     14 
     15// should render for posts 
     16if ( ! defined( 'DS_PLUGIN_FOR_PAGES' ) ) 
     17    define( 'DS_PLUGIN_FOR_PAGES', true ); 
     18 
     19// should render for posts 
     20if ( ! defined( 'DS_PLUGIN_FOR_POSTS' ) ) 
     21    define( 'DS_PLUGIN_FOR_POSTS', true ); 
     22 
     23// should render on page on front 
     24if ( ! defined( 'DS_PLUGIN_FOR_FRONT_PAGE' ) ) 
     25    define( 'DS_PLUGIN_FOR_FRONT_PAGE', true ); 
     26 
     27// should render on page for posts 
     28if ( ! defined( 'DS_PLUGIN_FOR_POSTS_PAGE' ) ) 
     29    define( 'DS_PLUGIN_FOR_POSTS_PAGE', true ); 
     30 
     31// define theme localization domain 
     32define( 'DS_PLUGIN_I18N_DOMAIN', 'dynamic-sidebars' ); 
     33 
     34// custom field name 
     35define( 'DS_PLUGIN_CUSTOM_FIELD', 'dynamic_sidebar' ); 
     36 
     37// ------------------------------------------------------------ 
     38 
     39if ( ! function_exists( 'ds_plugin_install' ) ) : 
    1340 
    1441/** 
     
    1744 * Check if the wordpress version is 3.0.0 > if not deactive the plugin 
    1845 */ 
    19 function ds_install() { 
     46function ds_plugin_install() 
     47{ 
    2048    if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) { 
    21         // Deactivate our plugin 
     49        // Deactivate plugin 
    2250        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' ) ); 
     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' ) ) ); 
    2452    } 
     53 
     54    do_action( 'ds_plugin_install' ); 
    2555} 
    2656 
    27 /** 
    28  * Register the install function 
    29  */ 
    30 register_activation_hook( __FILE__, 'ds_install' ); 
     57register_activation_hook( __FILE__, 'ds_plugin_install' ); 
    3158 
    3259endif; 
     
    3461// ------------------------------------------------------------ 
    3562 
    36 if ( ! function_exists( 'ds_uninstall' ) ) : 
     63if ( ! function_exists( 'ds_plugin_uninstall' ) ) : 
    3764 
    3865/** 
     
    4168 * Uninstall the Dynamics Sidebars plugin and remove all saved data from Database 
    4269 */ 
    43 function ds_uninstall() { 
    44     // Get all pages 
    45     $allpages = get_posts('numberposts=-1&post_type=page&post_status=any'); 
     70function ds_plugin_uninstall() 
     71{ 
     72    global $wpdb; 
    4673 
    47     foreach( $allpages as $page ) { 
    48         delete_post_meta( $page->ID, 'dynamic_sidebar' ); 
    49     } 
     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' ); 
    5079} 
    5180 
    52 /** 
    53  * Register the uninstall function 
    54  */ 
    55 register_deactivation_hook( __FILE__, 'ds_uninstall' ); 
     81register_deactivation_hook( __FILE__, 'ds_plugin_uninstall' ); 
    5682 
    5783endif; 
    5884 
    59 // include our sidebar file 
    60 include_once 'ds.class.php'; 
     85// ------------------------------------------------------------ 
     86 
     87include_once( 'includes/api.php' ); 
     88include_once( 'includes/class-dynamic-sidebars.php' ); 
  • dynamics-sidebars/trunk/readme.txt

    r449741 r570487  
    22 
    33Contributors: alyssonweb 
    4 Tags: sidebar, widget, dynamic, different 
     4Tags: sidebar, custom, dynamic, widget, different 
    55Requires at least: 3.0 
    6 Tested up to: 3.2.1 
    7 Stable tag: 0.1.3 
    8  
    9 Add a custom field to add widget area for Pages. 
     6Tested up to: 3.4.1 
     7Stable tag: 1.0.0 
     8License: GPLv2 or later 
     9License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     10Donate 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 
     12Create a custom widget area (sidebar) for pages, posts and custom post types. 
    1013 
    1114 
    1215== Description == 
    1316 
    14 Add a custom options to Pages so Pages can display a different sidebars. 
    15  
    1617**Please Note** 
    1718 
    18 * Requires at least: 3.0 
    19 * Tested up to: 3.2.1 
     19* Requires at least wp version: 3.0 
    2020 
    2121 
     
    3535 
    36361. After activating the plugin 
    37 1. 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 ) 
    38 1. Enter the name of your dynamic sidebar, recommend to put the same name as your page title 
    39 1. Go to the Appearance > Widget page and place anything on your new widget area 
     371. 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 ) 
     381. Enter the name for your sidebar area (recommend to use same as your page title) 
     391. Go to the Appearance > Widgets and place anything onto your new widget area 
    40401. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 
    4141 
    4242`<?php 
    43     // Get the current post sidebar area 
    44     $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
    45      
    46     // Display the sidebar area 
    47     dynamic_sidebar( $dynamic_sidebar ); 
     43    dynamic_sidebar( get_the_sidebar() ); 
    4844?>` 
    4945 
     
    5248 
    5349`<?php 
    54     // Get the current post sidebar area 
    55     $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
    56  
    57     if ( is_active_sidebar( $dynamic_sidebar ) ) { 
    58         // Do your stuff 
     50    $sidebar = get_the_sidebar(); 
     51    if ( is_active_sidebar( $sidebar ) ) { 
     52        dynamic_sidebar( $sidebar ); 
    5953    } 
    6054?>` 
    6155 
     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 
     72Many filters and actions to hook on to. 
     73 
    6274 
    6375**Changing before_widget and after_widget** 
     
    6577On your functions.php file just add the following code, don't forget to change 'function_to_return_my_new_*' to your own function 
    6678`<?php 
    67     add_filter( 'ds_sidebar_description', 'function_to_return_my_new_sidebar_description' ); 
    68     add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
    69     add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
    70     add_filter( 'ds_before_title', 'function_to_return_my_new_before_title' ); 
    71     add_filter( 'ds_after_title', 'function_to_return_my_new_after_title' ); 
     79    add_filter( 'ds_sidebar_args', 'function to return my sidebar items' ); 
    7280?>` 
    7381 
     
    7684 
    7785`<?php 
    78     add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
    79     add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
    80  
    81     function ds_before_widget(){ 
    82         return '<div id="%1$s" class="widget-container %2$s">'; 
     86    add_filter( 'ds_sidebar_args', 'my_sidebar_args' ); 
     87 
     88    function my_sidebar_args( $defaults ) { 
     89        $args = array( 
     90            'description'   => 'My widget area', 
     91            'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 
     92            'after_widget'  => '</li>', 'after_widget', 
     93            'before_title'  => '<h3 class="widget-title">', 
     94            'after_title'   => '</h3>', 'after_title', 
     95        ); 
     96 
     97        return $args; 
    8398    } 
    84  
    85     function ds_after_widget(){ 
    86         return '</div>'; 
    87     } 
    8899?>` 
    89100 
    90101 
    91102== Installation == 
     103 
     104**Please Note** 
     105 
     106* Requires at least: 3.0 
     107 
    92108 
    93109**Install** 
     
    103119 
    104120 
    105 **Usage** 
    106  
    107 1. After activating the plugin 
    108 1. 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 ) 
    109 1. Enter the name of your dynamic sidebar, recommend to put the same name as your page title 
    110 1. Go to the Appearance > Widget page and place anything on your new widget area 
    111 1. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 
    112  
    113 `<?php 
    114     // Get the current post sidebar area 
    115     $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
    116      
    117     // Display the sidebar area 
    118     dynamic_sidebar( $dynamic_sidebar ); 
    119 ?>` 
    120  
    121  
    122 **Checking if sidebar is active** 
    123  
    124 `<?php 
    125     // Get the current post sidebar area 
    126     $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 
    127  
    128     if ( is_active_sidebar( $dynamic_sidebar ) ) { 
    129         // Do your stuff 
    130     } 
    131 ?>` 
    132  
    133  
    134 **Changing before_widget and after_widget** 
    135  
    136 On your functions.php file just add the following code, don't forget to change 'function_to_return_my_new_*' to your own function 
    137 `<?php 
    138     add_filter( 'ds_sidebar_description', 'function_to_return_my_new_sidebar_description' ); 
    139     add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
    140     add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
    141     add_filter( 'ds_before_title', 'function_to_return_my_new_before_title' ); 
    142     add_filter( 'ds_after_title', 'function_to_return_my_new_after_title' ); 
    143 ?>` 
    144  
    145  
    146 ***Here is an example:*** 
    147  
    148 `<?php 
    149     add_filter( 'ds_before_widget', 'function_to_return_my_new_before_widget' ); 
    150     add_filter( 'ds_after_widget', 'function_to_return_my_new_after_widget' ); 
    151  
    152     function ds_before_widget(){ 
    153         return '<div id="%1$s" class="widget-container %2$s">'; 
    154     } 
    155  
    156     function ds_after_widget(){ 
    157         return '</div>'; 
    158     } 
    159 ?>` 
    160  
    161  
    162 = 0.1 = 
    163  
    164 * First version of the plugin. 
    165  
    166 = 0.1.1 = 
    167  
    168 * Changes to the readme.txt 
     121== Screenshots == 
     122 
     1231. Pages/Posts/Custom Post Types Edit Page 
     1242. Quick Edit 
     1253. Bulk Edit 
     126 
     127== Frequently Asked Questions == 
     128 
     129No FAQ yet. 
     130 
     131== Changelog == 
     132 
     133= 1.0.0 = 
     134 
     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: 
     141* the_sidebar( $fallback = '', $echo = false ) 
     142* get_the_sidebar( $post_id = 0 ) 
     143* get_custom_sidebars() 
     144* get_all_sidebars() 
     145* Added FILTERS: 
     146* the_sidebar 
     147* ds_save_permissions 
     148* ds_save_ajax_message 
     149* ds_save_ajax 
     150* 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) 
    169164 
    170165= 0.1.2 = 
    171166 
    172167* Added install and uninstall functions 
    173 * Checked version 3.0 > 3.2.1 
    174168* Changes to 'readme.txt' 
    175169* Requires at least: 3.0 
    176 * Tested up to: 3.2.1 
    177  
     170* Tested up to: 3.4.1 
     171 
     172= 0.1 = 
     173 
     174* First release. 
    178175 
    179176== Upgrade Notice == 
    180177 
     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 
    181217= 0.1 = 
    182218 
    183 First version of the plugin. Stable version. 
    184  
    185 = 0.1.1 = 
    186  
    187 Minor changes and change to 'readme.txt' 
    188  
    189 = 0.1.2 = 
    190  
    191 Added install and uninstall functions and others minor changes 
     219* First release. 
     220 
     221== Internationalization (i18n) == 
     222 
     223This plugin has been translated into the languages listed below: 
     224 
     225* pt_BR - Portuguese Brazil. 
     226 
     227If you're interested in doing a translation into your language, please let me know. 
Note: See TracChangeset for help on using the changeset viewer.