Changeset 449734
- Timestamp:
- 10/11/2011 05:16:49 AM (14 years ago)
- Location:
- dynamics-sidebars/trunk
- Files:
-
- 4 edited
-
ds.class.php (modified) (7 diffs)
-
dynamics-sidebars.php (modified) (1 diff)
-
index.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
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(); 6 2 7 3 // Check if this class does not already exists … … 32 28 public function __construct() { 33 29 // 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 ); 41 38 42 39 // Hook our actions … … 101 98 102 99 <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" /> 104 101 105 102 <?php … … 147 144 // Save the data to database 148 145 update_post_meta( $post_id, 'dynamic_sidebar', $new_data ); 149 } elseif ('' == $new && $old) {146 } elseif ('' == $new_data && $old_data) { 150 147 // 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 ); 152 149 } 153 150 } … … 192 189 array( 193 190 '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 function191 'id' => sanitize_title( $meta_value ), // Name and ID should be the same to work with is_active_sidebar function 195 192 'description' => apply_filters( 'ds_sidebar_description', __( $meta_value . ' Widget Area', 'dynamics_sidebars' ) ), 196 193 'before_widget' => apply_filters( 'ds_before_widget', '<div id="%1$s" class="widget-container %2$s">' ), … … 206 203 207 204 /** 208 * Friendly String209 *210 * Convert the passed string to a frindly format for URLs, File Names etc...211 *212 * @access public213 * @param string The string to convert214 * @param int The max number of characters to return215 * @return string New friendly string216 */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 /**240 205 * Filter Field 241 206 * … … 251 216 } // End: Dynamics_Sidebars 252 217 218 // ------------------------------------------------------------ 219 220 /** 221 * Init Dynamics Sidebars 222 */ 223 $ds = new Dynamics_Sidebars; 224 225 // ------------------------------------------------------------ 226 253 227 endif; 254 255 // ------------------------------------------------------------256 257 if ( ! function_exists( 'init_dynamics_sidebars' ) ) :258 259 /**260 * Init Dynamics Sidebars261 *262 * Initialize the Dynamics_Sidebars class263 *264 * @return void265 */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 12 if ( ! function_exists( 'ds_install' ) ) : 4 13 5 14 /** 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 */ 19 function 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 */ 30 register_activation_hook( __FILE__, 'ds_install' ); 31 32 endif; 33 34 // ------------------------------------------------------------ 35 36 if ( ! function_exists( 'ds_uninstall' ) ) : 37 38 /** 39 * Uninstall 40 * 41 * Uninstall the Dynamics Sidebars plugin and remove all saved data from Database 42 */ 43 function 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 */ 55 register_deactivation_hook( __FILE__, 'ds_uninstall' ); 56 57 endif; 14 58 15 59 // 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 4 4 Tags: sidebar, widget, dynamic, different 5 5 Requires at least: 3.0 6 Tested up to: 3. 1.27 Stable tag: 0.1. 16 Tested up to: 3.2.1 7 Stable tag: 0.1.2 8 8 9 Add a custom options to Pages so they can have different sidebars9 Add a custom field to add widget area for Pages. 10 10 11 11 == Description == 12 12 13 Add a custom options to Pages so they can have different sidebars widgets areas 13 Add 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 22 1. Unzip the dynamics-sidebars.zip file. 23 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. 24 25 **Activate** 26 27 1. In your WordPress administration, go to the Plugins page 28 1. Activate the Dynamics Sidebars plugin. 29 30 **Usage** 31 32 1. After activating the plugin 33 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 ) 34 1. Enter the name of your dynamic sidebar, recommend to put the same name as your page title 35 1. Go to the Appearance > Widget page and place anything on your new widget area 36 1. 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 58 On 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 ?>` 14 81 15 82 == Installation == 16 83 17 Install 84 **Install** 18 85 19 86 1. Unzip the dynamics-sidebars.zip file. 87 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. 20 88 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** 24 90 25 91 1. In your WordPress administration, go to the Plugins page 92 1. Activate the Dynamics Sidebars plugin. 26 93 27 2. Activate the Dynamics Sidebars plugin. 94 **Usage** 28 95 29 3. Go to the Pages > Add or New and you should see the Dynamic Sidebar Metabox on the side 96 1. After activating the plugin 97 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 ) 98 1. Enter the name of your dynamic sidebar, recommend to put the same name as your page title 99 1. Go to the Appearance > Widget page and place anything on your new widget area 100 1. On either files page.php, sidebar.php, sidebar-{custom}.php or custom-template.php just add the following code: 30 101 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 ?>` 32 109 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 ); 34 114 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 ?>` 36 119 120 **Changing before_widget and after_widget** 37 121 38 <?php 39 $dynamic_sidebar = get_post_meta( $post->ID, 'dynamic_sidebar', true ); 40 dynamic_sidebar( $dynamic_sidebar ); 41 ?> 122 On 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 ?>` 42 145 43 146 = 0.1 = 44 45 147 * First version of the plugin. 46 148 47 149 = 0.1.1 = 150 * Changes to the readme.txt 48 151 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 50 158 51 159 == Upgrade Notice == 52 160 53 161 = 0.1 = 54 55 162 First version of the plugin. Stable version. 56 163 57 164 = 0.1.1 = 165 Minor changes and change to 'readme.txt' 58 166 59 Changes to "readme.txt" 167 = 0.1.2 = 168 Added install and uninstall functions and others minor changes
Note: See TracChangeset
for help on using the changeset viewer.