Changeset 570487
- Timestamp:
- 07/11/2012 07:04:28 AM (14 years ago)
- Location:
- dynamics-sidebars/trunk
- Files:
-
- 17 added
- 1 deleted
- 2 edited
-
assets (added)
-
assets/banner-772×250.jpg (added)
-
css (added)
-
css/style.css (added)
-
ds.class.php (deleted)
-
dynamics-sidebars.php (modified) (4 diffs)
-
includes (added)
-
includes/api.php (added)
-
includes/class-dynamic-sidebars.php (added)
-
js (added)
-
js/script.js (added)
-
languages (added)
-
languages/dynamics-sidebars-pt_BR.mo (added)
-
languages/dynamics-sidebars-pt_BR.po (added)
-
languages/dynamics-sidebars.pot (added)
-
readme.txt (modified) (6 diffs)
-
screenshot-1.png (added)
-
screenshot-2.png (added)
-
screenshot-3.png (added)
-
uninstall.php (added)
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 2 3 /** 3 4 * 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. 5 6 * Author: Alysson Bortoli 6 7 * Author Name: Alysson Bortoli 7 * Author URI: http://twitter.com/ #!/akbortoli8 * Version: 0.1.39 * License: GPLv2 8 * Author URI: http://twitter.com/akbortoli 9 * Version: 1.0.0 10 * License: GPLv2 or later 10 11 */ 11 12 12 if ( ! function_exists( 'ds_install' ) ) : 13 // ------------------------------------------------------------ 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 ); 22 23 // should render on page on front 24 if ( ! defined( 'DS_PLUGIN_FOR_FRONT_PAGE' ) ) 25 define( 'DS_PLUGIN_FOR_FRONT_PAGE', true ); 26 27 // should render on page for posts 28 if ( ! defined( 'DS_PLUGIN_FOR_POSTS_PAGE' ) ) 29 define( 'DS_PLUGIN_FOR_POSTS_PAGE', true ); 30 31 // define theme localization domain 32 define( 'DS_PLUGIN_I18N_DOMAIN', 'dynamic-sidebars' ); 33 34 // custom field name 35 define( 'DS_PLUGIN_CUSTOM_FIELD', 'dynamic_sidebar' ); 36 37 // ------------------------------------------------------------ 38 39 if ( ! function_exists( 'ds_plugin_install' ) ) : 13 40 14 41 /** … … 17 44 * Check if the wordpress version is 3.0.0 > if not deactive the plugin 18 45 */ 19 function ds_install() { 46 function ds_plugin_install() 47 { 20 48 if ( version_compare( get_bloginfo( 'version' ), '3.0', '<' ) ) { 21 // Deactivate ourplugin49 // Deactivate plugin 22 50 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' ) ) ); 24 52 } 53 54 do_action( 'ds_plugin_install' ); 25 55 } 26 56 27 /** 28 * Register the install function 29 */ 30 register_activation_hook( __FILE__, 'ds_install' ); 57 register_activation_hook( __FILE__, 'ds_plugin_install' ); 31 58 32 59 endif; … … 34 61 // ------------------------------------------------------------ 35 62 36 if ( ! function_exists( 'ds_ uninstall' ) ) :63 if ( ! function_exists( 'ds_plugin_uninstall' ) ) : 37 64 38 65 /** … … 41 68 * Uninstall the Dynamics Sidebars plugin and remove all saved data from Database 42 69 */ 43 function ds_ uninstall() {44 // Get all pages 45 $allpages = get_posts('numberposts=-1&post_type=page&post_status=any');70 function ds_plugin_uninstall() 71 { 72 global $wpdb; 46 73 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' ); 50 79 } 51 80 52 /** 53 * Register the uninstall function 54 */ 55 register_deactivation_hook( __FILE__, 'ds_uninstall' ); 81 register_deactivation_hook( __FILE__, 'ds_plugin_uninstall' ); 56 82 57 83 endif; 58 84 59 // include our sidebar file 60 include_once 'ds.class.php'; 85 // ------------------------------------------------------------ 86 87 include_once( 'includes/api.php' ); 88 include_once( 'includes/class-dynamic-sidebars.php' ); -
dynamics-sidebars/trunk/readme.txt
r449741 r570487 2 2 3 3 Contributors: alyssonweb 4 Tags: sidebar, widget, dynamic, different4 Tags: sidebar, custom, dynamic, widget, different 5 5 Requires 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. 6 Tested up to: 3.4.1 7 Stable tag: 1.0.0 8 License: GPLv2 or later 9 License 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¤cy_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. 10 13 11 14 12 15 == Description == 13 16 14 Add a custom options to Pages so Pages can display a different sidebars.15 16 17 **Please Note** 17 18 18 * Requires at least: 3.0 19 * Tested up to: 3.2.1 19 * Requires at least wp version: 3.0 20 20 21 21 … … 35 35 36 36 1. 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 title39 1. Go to the Appearance > Widget page and place anything onyour new widget area37 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 40 1. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 41 41 42 42 `<?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() ); 48 44 ?>` 49 45 … … 52 48 53 49 `<?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 ); 59 53 } 60 54 ?>` 61 55 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 Many filters and actions to hook on to. 73 62 74 63 75 **Changing before_widget and after_widget** … … 65 77 On your functions.php file just add the following code, don't forget to change 'function_to_return_my_new_*' to your own function 66 78 `<?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' ); 72 80 ?>` 73 81 … … 76 84 77 85 `<?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; 83 98 } 84 85 function ds_after_widget(){86 return '</div>';87 }88 99 ?>` 89 100 90 101 91 102 == Installation == 103 104 **Please Note** 105 106 * Requires at least: 3.0 107 92 108 93 109 **Install** … … 103 119 104 120 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 123 1. Pages/Posts/Custom Post Types Edit Page 124 2. Quick Edit 125 3. Bulk Edit 126 127 == Frequently Asked Questions == 128 129 No 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) 169 164 170 165 = 0.1.2 = 171 166 172 167 * Added install and uninstall functions 173 * Checked version 3.0 > 3.2.1174 168 * Changes to 'readme.txt' 175 169 * 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. 178 175 179 176 == Upgrade Notice == 180 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 181 217 = 0.1 = 182 218 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 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.
Note: See TracChangeset
for help on using the changeset viewer.