WordPress.org

Plugin Directory

Changeset 819367


Ignore:
Timestamp:
12/12/13 02:35:26 (21 months ago)
Author:
aaroncampbell
Message:

Tag version 1.1.0 that extends text widget and replaces existing class

Location:
better-text-widget
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • better-text-widget/tags/1.1.0/better-text-widget.php

    r202389 r819367  
    22/** 
    33 * Plugin Name: Better Text Widget 
    4  * Plugin URI: http://xavisys.com/wordpress-plugins/better-text-widget/ 
    5  * Description: An improved text widget that adds a class to each instance (based off title) 
    6  * Version: 1.0.0 
     4 * Plugin URI: http://ran.ge/wordpress-plugin/better-text-widget/ 
     5 * Description: Improves text widget by adding a class to each instance based off title 
     6 * Version: 1.1.0 
    77 * Author: Aaron D. Campbell 
    8  * Author URI: http://xavisys.com/ 
     8 * Author URI: http://ran.ge/ 
     9 * License: GPLv2 or later 
    910 */ 
    1011 
    11 /*  Copyright 2006  Aaron D. Campbell  (email : wp_plugins@xavisys.com) 
    12  
    13     This program is free software; you can redistribute it and/or modify 
    14     it under the terms of the GNU General Public License as published by 
    15     the Free Software Foundation; either version 2 of the License, or 
    16     (at your option) any later version. 
    17  
    18     This program is distributed in the hope that it will be useful, 
    19     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    21     GNU General Public License for more details. 
    22  
    23     You should have received a copy of the GNU General Public License 
    24     along with this program; if not, write to the Free Software 
    25     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    26 */ 
    27 /** 
    28  * wpBetterTextWidget is the class that handles ALL of the plugin functionality. 
    29  * It helps us avoid name collisions 
    30  * http://codex.wordpress.org/Writing_a_Plugin#Avoiding_Function_Name_Collisions 
    31  */ 
    32  
    33 class wpBetterTextWidget 
    34 { 
    35     /** 
    36      * Displays the better text widge 
    37      * 
    38      * @param array $args - Widget Settings 
    39      * @param array|int $widget_args - Widget Number 
    40      */ 
    41     public function display($args, $widget_args = 1) { 
    42         extract( $args, EXTR_SKIP ); 
    43         if ( is_numeric($widget_args) ) 
    44             $widget_args = array( 'number' => $widget_args ); 
    45         $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 
    46         extract( $widget_args, EXTR_SKIP ); 
    47  
    48         $options = get_option('better_text_widget'); 
    49         if ( !isset($options[$number]) ) 
    50             return; 
    51  
    52         $title = apply_filters('widget_title', $options[$number]['title']); 
    53         $text = apply_filters( 'widget_text', $options[$number]['text'] ); 
    54     ?> 
    55             <?php echo $before_widget; ?> 
    56                 <?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> 
    57                 <div class="textwidget"><?php echo $text; ?></div> 
    58             <?php echo $after_widget; ?> 
    59     <?php 
     12function better_text_widget_widgets_init() { 
     13    class wpBetterTextWidget extends WP_Widget_Text { 
     14        function widget( $args, $instance ) { 
     15            $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 
     16            $additional_class = sanitize_title_with_dashes( $title ); 
     17            $args['before_widget'] = str_replace( 'widget_text', 'widget_text ' . $additional_class, $args['before_widget'] ); 
     18            parent::widget( $args, $instance ); 
     19        } 
    6020    } 
    6121 
    62     /** 
    63      * Sets up admin forms to manage widgets 
    64      * 
    65      * @param array|int $widget_args - Widget Number 
    66      */ 
    67     public function control($widget_args) { 
    68         global $wp_registered_widgets; 
    69         static $updated = false; 
    70  
    71         if ( is_numeric($widget_args) ) 
    72             $widget_args = array( 'number' => $widget_args ); 
    73         $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 
    74         extract( $widget_args, EXTR_SKIP ); 
    75  
    76         $options = get_option('better_text_widget'); 
    77         if ( !is_array($options) ) 
    78             $options = array(); 
    79  
    80         if ( !$updated && !empty($_POST['sidebar']) ) { 
    81             $sidebar = (string) $_POST['sidebar']; 
    82  
    83             $sidebars_widgets = wp_get_sidebars_widgets(); 
    84             if ( isset($sidebars_widgets[$sidebar]) ) 
    85                 $this_sidebar =& $sidebars_widgets[$sidebar]; 
    86             else 
    87                 $this_sidebar = array(); 
    88  
    89             foreach ( $this_sidebar as $_widget_id ) { 
    90                 if ( array( $this, 'display' ) == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) { 
    91                     $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; 
    92                     if ( !in_array( "better-text-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed. 
    93                         unset($options[$widget_number]); 
    94                 } 
    95             } 
    96  
    97             foreach ( (array) $_POST['better-text-widget'] as $widget_number => $widget_text ) { 
    98                 if ( !isset($widget_text['text']) && isset($options[$widget_number]) ) // user clicked cancel 
    99                     continue; 
    100                 $title = strip_tags(stripslashes($widget_text['title'])); 
    101                 if ( current_user_can('unfiltered_html') ) 
    102                     $text = stripslashes( $widget_text['text'] ); 
    103                 else 
    104                     $text = stripslashes(wp_filter_post_kses( $widget_text['text'] )); 
    105                 $options[$widget_number] = compact( 'title', 'text' ); 
    106             } 
    107  
    108             update_option('better_text_widget', $options); 
    109             $updated = true; 
    110         } 
    111  
    112         if ( -1 == $number ) { 
    113             $title = ''; 
    114             $text = ''; 
    115             $number = '%i%'; 
    116         } else { 
    117             $title = attribute_escape($options[$number]['title']); 
    118             $text = format_to_edit($options[$number]['text']); 
    119         } 
    120     ?> 
    121             <p> 
    122                 <input class="widefat" id="better-text-title-<?php echo $number; ?>" name="better-text-widget[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /> 
    123                 <textarea class="widefat" rows="16" cols="20" id="better-text-text-<?php echo $number; ?>" name="better-text-widget[<?php echo $number; ?>][text]"><?php echo $text; ?></textarea> 
    124                 <input type="hidden" name="better-text-widget[<?php echo $number; ?>][submit]" value="1" /> 
    125             </p> 
    126     <?php 
    127     } 
    128  
    129     /** 
    130      * Registers widget in such a way as to allow multiple instances of it 
    131      * 
    132      * @see wp-includes/widgets.php 
    133      */ 
    134     public function register() { 
    135         if ( !$options = get_option('better_text_widget') ) 
    136             $options = array(); 
    137         $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML with classname')); 
    138         $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'better-text'); 
    139         $name = __('Better Text'); 
    140  
    141         $id = false; 
    142         foreach ( array_keys($options) as $o ) { 
    143             // Old widgets can have null values for some reason 
    144             if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) ) 
    145                 continue; 
    146             $id = "better-text-$o"; // Never never never translate an id 
    147             $ops = $widget_ops; 
    148             $ops['classname'] .= ' ' . sanitize_title_with_dashes($options[$o]['title']); 
    149             wp_register_sidebar_widget($id, $name, array( $this, 'display' ), $ops, array( 'number' => $o )); 
    150             wp_register_widget_control($id, $name, array( $this, 'control' ), $control_ops, array( 'number' => $o )); 
    151         } 
    152  
    153         // If there are none, we register the widget's existance with a generic template 
    154         if ( !$id ) { 
    155             wp_register_sidebar_widget( 'better-text-1', $name, array( $this, 'display' ), $widget_ops, array( 'number' => -1 ) ); 
    156             wp_register_widget_control( 'better-text-1', $name, array( $this, 'control' ), $control_ops, array( 'number' => -1 ) ); 
    157         } 
    158     } 
     22    register_widget( 'wpBetterTextWidget' ); 
    15923} 
    160 // Instantiate our class 
    161 $wpBetterTextWidget = new wpBetterTextWidget(); 
    162  
    163 /** 
    164  * Add filters and actions 
    165  */ 
    166 add_action('widgets_init', array($wpBetterTextWidget, 'register')); 
     24add_action( 'widgets_init', 'better_text_widget_widgets_init' ); 
  • better-text-widget/tags/1.1.0/readme.txt

    r110322 r819367  
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%40xavisys%2ecom&item_name=Better%20Text%20Widget&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8 
    44Tags: text, widget 
    5 Requires at least: 2.7 
    6 Tested up to: 2.7.1 
    7 Stable tag: 1.0.0 
     5Requires at least: 3.5 
     6Tested up to: 3.8 
     7Stable tag: 1.1.0 
    88 
    9 A widget improves upon the built-in text widget by adding a class to each instance of the widget.  The class is based on the title of the widget. Requires PHP5. 
     9A widget improves upon the built-in text widget by adding a class to each instance of the widget, based on the title. 
    1010 
    1111== Description == 
    1212 
    13 A widget improves upon the built-in text widget by adding a class to each 
    14 instance of the widget.  The class is based on the title of the widget. Requires 
    15 PHP5. 
     13A widget improves upon the built-in text widget by adding a class to each instance of the widget, based on the title. 
    1614 
    1715== Installation == 
    1816 
    19 1. Verify that you have PHP5, which is required for this plugin. 
    20 1. Upload the whole `better-text-widget` directory to the `/wp-content/plugins/` directory 
    21 1. Activate the plugin through the 'Plugins' menu in WordPress 
     171. Use automatic installer to install and active the plugin. 
    2218 
    23 == Frequently Asked Questions == 
     19== Upgrade Notice == 
    2420 
    25 = Can I have use than one instance of this widget? = 
     21= 1.1.0 = 
     22More efficient and based off the new text widget code 
    2623 
    27 Yes, just the like the built-in text widget, Better Text Widget employs the multi-widget pattern, which allows you to not only have more than one instance of this widget on your site, but even allows more than one instance of this widget in a single sidebar. 
     24= 1.0.0 = 
     25Brand new version 
     26 
     27== Changelog == 
     28 
     29= 1.0.0 = 
     30* Now extends the existing text widget and simply replaces it's class 
     31 
     32= 1.0.0 = 
     33* Original Version 
  • better-text-widget/trunk/better-text-widget.php

    r202389 r819367  
    22/** 
    33 * Plugin Name: Better Text Widget 
    4  * Plugin URI: http://xavisys.com/wordpress-plugins/better-text-widget/ 
    5  * Description: An improved text widget that adds a class to each instance (based off title) 
    6  * Version: 1.0.0 
     4 * Plugin URI: http://ran.ge/wordpress-plugin/better-text-widget/ 
     5 * Description: Improves text widget by adding a class to each instance based off title 
     6 * Version: 1.1.0 
    77 * Author: Aaron D. Campbell 
    8  * Author URI: http://xavisys.com/ 
     8 * Author URI: http://ran.ge/ 
     9 * License: GPLv2 or later 
    910 */ 
    1011 
    11 /*  Copyright 2006  Aaron D. Campbell  (email : wp_plugins@xavisys.com) 
    12  
    13     This program is free software; you can redistribute it and/or modify 
    14     it under the terms of the GNU General Public License as published by 
    15     the Free Software Foundation; either version 2 of the License, or 
    16     (at your option) any later version. 
    17  
    18     This program is distributed in the hope that it will be useful, 
    19     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    21     GNU General Public License for more details. 
    22  
    23     You should have received a copy of the GNU General Public License 
    24     along with this program; if not, write to the Free Software 
    25     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    26 */ 
    27 /** 
    28  * wpBetterTextWidget is the class that handles ALL of the plugin functionality. 
    29  * It helps us avoid name collisions 
    30  * http://codex.wordpress.org/Writing_a_Plugin#Avoiding_Function_Name_Collisions 
    31  */ 
    32  
    33 class wpBetterTextWidget 
    34 { 
    35     /** 
    36      * Displays the better text widge 
    37      * 
    38      * @param array $args - Widget Settings 
    39      * @param array|int $widget_args - Widget Number 
    40      */ 
    41     public function display($args, $widget_args = 1) { 
    42         extract( $args, EXTR_SKIP ); 
    43         if ( is_numeric($widget_args) ) 
    44             $widget_args = array( 'number' => $widget_args ); 
    45         $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 
    46         extract( $widget_args, EXTR_SKIP ); 
    47  
    48         $options = get_option('better_text_widget'); 
    49         if ( !isset($options[$number]) ) 
    50             return; 
    51  
    52         $title = apply_filters('widget_title', $options[$number]['title']); 
    53         $text = apply_filters( 'widget_text', $options[$number]['text'] ); 
    54     ?> 
    55             <?php echo $before_widget; ?> 
    56                 <?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> 
    57                 <div class="textwidget"><?php echo $text; ?></div> 
    58             <?php echo $after_widget; ?> 
    59     <?php 
     12function better_text_widget_widgets_init() { 
     13    class wpBetterTextWidget extends WP_Widget_Text { 
     14        function widget( $args, $instance ) { 
     15            $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 
     16            $additional_class = sanitize_title_with_dashes( $title ); 
     17            $args['before_widget'] = str_replace( 'widget_text', 'widget_text ' . $additional_class, $args['before_widget'] ); 
     18            parent::widget( $args, $instance ); 
     19        } 
    6020    } 
    6121 
    62     /** 
    63      * Sets up admin forms to manage widgets 
    64      * 
    65      * @param array|int $widget_args - Widget Number 
    66      */ 
    67     public function control($widget_args) { 
    68         global $wp_registered_widgets; 
    69         static $updated = false; 
    70  
    71         if ( is_numeric($widget_args) ) 
    72             $widget_args = array( 'number' => $widget_args ); 
    73         $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 
    74         extract( $widget_args, EXTR_SKIP ); 
    75  
    76         $options = get_option('better_text_widget'); 
    77         if ( !is_array($options) ) 
    78             $options = array(); 
    79  
    80         if ( !$updated && !empty($_POST['sidebar']) ) { 
    81             $sidebar = (string) $_POST['sidebar']; 
    82  
    83             $sidebars_widgets = wp_get_sidebars_widgets(); 
    84             if ( isset($sidebars_widgets[$sidebar]) ) 
    85                 $this_sidebar =& $sidebars_widgets[$sidebar]; 
    86             else 
    87                 $this_sidebar = array(); 
    88  
    89             foreach ( $this_sidebar as $_widget_id ) { 
    90                 if ( array( $this, 'display' ) == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) { 
    91                     $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; 
    92                     if ( !in_array( "better-text-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed. 
    93                         unset($options[$widget_number]); 
    94                 } 
    95             } 
    96  
    97             foreach ( (array) $_POST['better-text-widget'] as $widget_number => $widget_text ) { 
    98                 if ( !isset($widget_text['text']) && isset($options[$widget_number]) ) // user clicked cancel 
    99                     continue; 
    100                 $title = strip_tags(stripslashes($widget_text['title'])); 
    101                 if ( current_user_can('unfiltered_html') ) 
    102                     $text = stripslashes( $widget_text['text'] ); 
    103                 else 
    104                     $text = stripslashes(wp_filter_post_kses( $widget_text['text'] )); 
    105                 $options[$widget_number] = compact( 'title', 'text' ); 
    106             } 
    107  
    108             update_option('better_text_widget', $options); 
    109             $updated = true; 
    110         } 
    111  
    112         if ( -1 == $number ) { 
    113             $title = ''; 
    114             $text = ''; 
    115             $number = '%i%'; 
    116         } else { 
    117             $title = attribute_escape($options[$number]['title']); 
    118             $text = format_to_edit($options[$number]['text']); 
    119         } 
    120     ?> 
    121             <p> 
    122                 <input class="widefat" id="better-text-title-<?php echo $number; ?>" name="better-text-widget[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /> 
    123                 <textarea class="widefat" rows="16" cols="20" id="better-text-text-<?php echo $number; ?>" name="better-text-widget[<?php echo $number; ?>][text]"><?php echo $text; ?></textarea> 
    124                 <input type="hidden" name="better-text-widget[<?php echo $number; ?>][submit]" value="1" /> 
    125             </p> 
    126     <?php 
    127     } 
    128  
    129     /** 
    130      * Registers widget in such a way as to allow multiple instances of it 
    131      * 
    132      * @see wp-includes/widgets.php 
    133      */ 
    134     public function register() { 
    135         if ( !$options = get_option('better_text_widget') ) 
    136             $options = array(); 
    137         $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML with classname')); 
    138         $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'better-text'); 
    139         $name = __('Better Text'); 
    140  
    141         $id = false; 
    142         foreach ( array_keys($options) as $o ) { 
    143             // Old widgets can have null values for some reason 
    144             if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) ) 
    145                 continue; 
    146             $id = "better-text-$o"; // Never never never translate an id 
    147             $ops = $widget_ops; 
    148             $ops['classname'] .= ' ' . sanitize_title_with_dashes($options[$o]['title']); 
    149             wp_register_sidebar_widget($id, $name, array( $this, 'display' ), $ops, array( 'number' => $o )); 
    150             wp_register_widget_control($id, $name, array( $this, 'control' ), $control_ops, array( 'number' => $o )); 
    151         } 
    152  
    153         // If there are none, we register the widget's existance with a generic template 
    154         if ( !$id ) { 
    155             wp_register_sidebar_widget( 'better-text-1', $name, array( $this, 'display' ), $widget_ops, array( 'number' => -1 ) ); 
    156             wp_register_widget_control( 'better-text-1', $name, array( $this, 'control' ), $control_ops, array( 'number' => -1 ) ); 
    157         } 
    158     } 
     22    register_widget( 'wpBetterTextWidget' ); 
    15923} 
    160 // Instantiate our class 
    161 $wpBetterTextWidget = new wpBetterTextWidget(); 
    162  
    163 /** 
    164  * Add filters and actions 
    165  */ 
    166 add_action('widgets_init', array($wpBetterTextWidget, 'register')); 
     24add_action( 'widgets_init', 'better_text_widget_widgets_init' ); 
  • better-text-widget/trunk/readme.txt

    r110322 r819367  
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%40xavisys%2ecom&item_name=Better%20Text%20Widget&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8 
    44Tags: text, widget 
    5 Requires at least: 2.7 
    6 Tested up to: 2.7.1 
    7 Stable tag: 1.0.0 
     5Requires at least: 3.5 
     6Tested up to: 3.8 
     7Stable tag: 1.1.0 
    88 
    9 A widget improves upon the built-in text widget by adding a class to each instance of the widget.  The class is based on the title of the widget. Requires PHP5. 
     9A widget improves upon the built-in text widget by adding a class to each instance of the widget, based on the title. 
    1010 
    1111== Description == 
    1212 
    13 A widget improves upon the built-in text widget by adding a class to each 
    14 instance of the widget.  The class is based on the title of the widget. Requires 
    15 PHP5. 
     13A widget improves upon the built-in text widget by adding a class to each instance of the widget, based on the title. 
    1614 
    1715== Installation == 
    1816 
    19 1. Verify that you have PHP5, which is required for this plugin. 
    20 1. Upload the whole `better-text-widget` directory to the `/wp-content/plugins/` directory 
    21 1. Activate the plugin through the 'Plugins' menu in WordPress 
     171. Use automatic installer to install and active the plugin. 
    2218 
    23 == Frequently Asked Questions == 
     19== Upgrade Notice == 
    2420 
    25 = Can I have use than one instance of this widget? = 
     21= 1.1.0 = 
     22More efficient and based off the new text widget code 
    2623 
    27 Yes, just the like the built-in text widget, Better Text Widget employs the multi-widget pattern, which allows you to not only have more than one instance of this widget on your site, but even allows more than one instance of this widget in a single sidebar. 
     24= 1.0.0 = 
     25Brand new version 
     26 
     27== Changelog == 
     28 
     29= 1.0.0 = 
     30* Now extends the existing text widget and simply replaces it's class 
     31 
     32= 1.0.0 = 
     33* Original Version 
Note: See TracChangeset for help on using the changeset viewer.