WordPress.org

Make WordPress Core

Changeset 10784


Ignore:
Timestamp:
03/14/09 16:34:08 (5 years ago)
Author:
ryan
Message:

Convert search to WP_Widget. Handle upgrade of widgets without settings. Make form and update override optional. see #8441

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r10782 r10784  
    7474     *  The newly calculated value of $instance should be returned. */ 
    7575    function update($new_instance, $old_instance) { 
    76         die('function WP_Widget::update() must be over-ridden in a sub-class.'); 
     76        return $new_instance; 
    7777    } 
    7878 
    7979    /** Echo a control form for the current instance. */ 
    8080    function form($instance) { 
    81         die('function WP_Widget::form() must be over-ridden in a sub-class.'); 
     81        echo '<p>' . __('There are no options for this widget.') . '</p>'; 
    8282    } 
    8383 
     
    252252 
    253253        if ( !is_array($settings) ) 
    254             return array(); 
     254            $settings = array(); 
    255255 
    256256        if ( !array_key_exists('_multiwidget', $settings) ) { 
     
    889889    // This test may need expanding. 
    890890    $single = false; 
    891     foreach ( array_keys($settings) as $number ) { 
    892         if ( !is_numeric($number) ) { 
    893             $single = true; 
    894             break; 
     891    if ( empty($settings) ) { 
     892        $single = true; 
     893    } else { 
     894        foreach ( array_keys($settings) as $number ) { 
     895            if ( !is_numeric($number) ) { 
     896                $single = true; 
     897                break; 
     898            } 
    895899        } 
    896900    } 
     
    10071011 */ 
    10081012class WP_Widget_Links extends WP_Widget { 
    1009      
     1013 
     1014    function WP_Widget_Links() { 
     1015        $widget_ops = array('description' => __( "Your blogroll" ) ); 
     1016        $this->WP_Widget('links', __('Links'), $widget_ops); 
     1017    } 
     1018 
    10101019    function widget( $args, $instance ) { 
    10111020        extract($args, EXTR_SKIP); 
     
    10611070 
    10621071/** 
    1063  * Display search widget. 
    1064  * 
    1065  * @since 2.2.0 
    1066  * 
    1067  * @param array $args Widget arguments. 
    1068  */ 
    1069 function wp_widget_search($args) { 
    1070     extract($args); 
    1071     echo $before_widget; 
    1072  
    1073     // Use current theme search form if it exists 
    1074     get_search_form(); 
    1075  
    1076     echo $after_widget; 
     1072 * Search widget class 
     1073 * 
     1074 * @since 2.8.0 
     1075 */ 
     1076class WP_Widget_Search extends WP_Widget { 
     1077 
     1078    function WP_Widget_Search() { 
     1079        $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") ); 
     1080        $this->WP_Widget('search', __('Search'), $widget_ops); 
     1081    } 
     1082 
     1083    function widget( $args, $instance ) { 
     1084        extract($args); 
     1085        echo $before_widget; 
     1086 
     1087        // Use current theme search form if it exists 
     1088        get_search_form(); 
     1089 
     1090        echo $after_widget;  
     1091    } 
    10771092} 
    10781093 
     
    22292244    wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control' ); 
    22302245 
    2231     $widget_ops = array('description' => __( "Your blogroll" ) ); 
    2232     $wp_widget_links = new WP_Widget_Links('links', __('Links'), $widget_ops); 
    2233     //$wp_widget_links->register(); 
     2246    new WP_Widget_Links(); 
    22342247 
    22352248    $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") ); 
     
    22372250    wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control' ); 
    22382251 
    2239     $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") ); 
    2240     wp_register_sidebar_widget('search', __('Search'), 'wp_widget_search', $widget_ops); 
     2252    new WP_Widget_Search(); 
    22412253 
    22422254    $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your blog") ); 
Note: See TracChangeset for help on using the changeset viewer.