WordPress.org

Make WordPress Core

Ticket #8441: widget_setup.patch

File widget_setup.patch, 6.3 KB (added by scribu, 9 years ago)
  • wp-includes/default-widgets.php

     
    1414 */
    1515class WP_Widget_Pages extends WP_Widget {
    1616
    17         function WP_Widget_Pages() {
    18                 $widget_ops = array('classname' => 'widget_pages', 'description' => __( "Your blog's WordPress Pages") );
    19                 $this->WP_Widget('pages', __('Pages'), $widget_ops);
     17        function setup() {
     18                $this->name = __('Pages');
     19                $this->id_base = 'pages';
     20                $this->widget_options = array('classname' => 'widget_pages', 'description' => __( "Your blog's WordPress Pages") );
    2021        }
    2122
    2223        function widget( $args, $instance ) {
     
    9091 */
    9192class WP_Widget_Links extends WP_Widget {
    9293
    93         function WP_Widget_Links() {
    94                 $widget_ops = array('description' => __( "Your blogroll" ) );
    95                 $this->WP_Widget('links', __('Links'), $widget_ops);
     94        function setup() {
     95                $this->name = __('Links');
     96                $this->id_base = 'links';
     97                $this->widget_options = array('description' => __( "Your blogroll" ) );
    9698        }
    9799
    98100        function widget( $args, $instance ) {
     
    150152 */
    151153class WP_Widget_Search extends WP_Widget {
    152154
    153         function WP_Widget_Search() {
    154                 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") );
    155                 $this->WP_Widget('search', __('Search'), $widget_ops);
     155        function setup() {
     156                $this->name = __('Search');
     157                $this->id_base = 'search';
     158                $this->widget_options = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") );
    156159        }
    157160
    158161        function widget( $args, $instance ) {
     
    173176 */
    174177class WP_Widget_Archives extends WP_Widget {
    175178
    176         function WP_Widget_Archives() {
    177                 $widget_ops = array('classname' => 'widget_archive', 'description' => __( "A monthly archive of your blog's posts") );
    178                 $this->WP_Widget('archives', __('Archives'), $widget_ops);
     179        function setup() {
     180                $this->name = __('Archives');
     181                $this->id_base = 'archives';
     182                $this->widget_options = array('classname' => 'widget_archive', 'description' => __( "A monthly archive of your blog's posts") );
    179183        }
    180184
    181185        function widget( $args, $instance ) {
     
    237241 */
    238242class WP_Widget_Meta extends WP_Widget {
    239243
    240         function WP_Widget_Meta() {
    241                 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
    242                 $this->WP_Widget('meta', __('Meta'), $widget_ops);
     244        function setup() {
     245                $this->name = __('Meta');
     246                $this->id_base = 'meta';
     247                $this->widget_options = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
    243248        }
    244249
    245250        function widget( $args, $instance ) {
     
    284289 */
    285290class WP_Widget_Calendar extends WP_Widget {
    286291
    287         function WP_Widget_Calendar() {
    288                 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( "A calendar of your blog's posts") );
    289                 $this->WP_Widget('calendar', __('Calendar'), $widget_ops);
     292        function setup() {
     293                $this->name = __('Calendar');
     294                $this->id_base = 'calendar';
     295                $this->widget_options = array('classname' => 'widget_calendar', 'description' => __( "A calendar of your blog's posts") );
    290296        }
    291297
    292298        function widget( $args, $instance ) {
     
    322328 */
    323329class WP_Widget_Text extends WP_Widget {
    324330
    325         function WP_Widget_Text() {
    326                 $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
    327                 $control_ops = array('width' => 400, 'height' => 350);
    328                 $this->WP_Widget('text', __('Text'), $widget_ops, $control_ops);
     331        function setup() {
     332                $this->name = __('Text');
     333                $this->id_base = 'text';
     334                $this->widget_options = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
    329335        }
    330336
    331337        function widget( $args, $instance ) {
     
    367373 */
    368374class WP_Widget_Categories extends WP_Widget {
    369375
    370         function WP_Widget_Categories() {
    371                 $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
    372                 $this->WP_Widget('categories', __('Categories'), $widget_ops);
     376        function setup() {
     377                $this->name = __('Categories');
     378                $this->id_base = 'categories';
     379                $this->widget_options = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
    373380        }
    374381
    375382        function widget( $args, $instance ) {
  • wp-includes/widgets.php

     
    3434
    3535        // Member functions that you must over-ride.
    3636
     37        /** Set up widget variables:
     38         * Mandatory are $id_base and $name
     39         */
     40        function setup() {
     41                die('function WP_Widget::setup() must be over-ridden in a sub-class.');
     42        }
     43
    3744        /** Echo the widget content.
    3845         *
    3946         * Subclasses should over-ride this function to generate their widget code.
     
    7178        /**
    7279         * PHP4 constructor
    7380         */
    74         function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) {
    75                 $this->__construct( $id_base, $name, $widget_options, $control_options );
     81        function WP_Widget() {
     82                $this->__construct();
    7683        }
    7784
    7885        /**
     
    8491         *       - width
    8592         *       - height
    8693         */
    87         function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
    88                 $this->id_base = $id_base;
    89                 $this->name = $name;
    90                 $this->option_name = 'widget_' . $id_base;
    91                 $this->widget_options = wp_parse_args( $widget_options, array('classname' => $this->option_name) );
    92                 $this->control_options = wp_parse_args( $control_options, array('id_base' => $this->id_base) );
     94        function __construct() {
     95                $this->setup();
    9396
     97                if ( empty($this->id_base) )
     98                        trigger_error("No id_base defined", E_USER_ERROR);
     99
     100                if ( empty($this->name) )
     101                        return trigger_error("No name defined", E_USER_ERROR);
     102
     103                $this->option_name = 'widget_' . $this->id_base;
     104                $this->widget_options = wp_parse_args( $this->widget_options, array('classname' => $this->option_name) );
     105                $this->control_options = wp_parse_args( $this->control_options, array('id_base' => $this->id_base) );
     106
    94107                //add_action( 'widgets_init', array( &$this, '_register' ) );
    95108        }
    96109
     
    10721085 */
    10731086function unregister_widget_control($id) {
    10741087        return wp_unregister_widget_control($id);
    1075 }
    1076  No newline at end of file
     1088}