Make WordPress Core

Changeset 10795


Ignore:
Timestamp:
03/16/2009 10:02:40 PM (15 years ago)
Author:
ryan
Message:

Separate default widgets from widgets API. Always load API. fixes #9349

Location:
trunk
Files:
1 added
3 edited

Legend:

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

    r10757 r10795  
    26152615 */
    26162616function wp_maybe_load_widgets() {
    2617     if ( !function_exists( 'dynamic_sidebar' ) ) {
    2618         require_once( ABSPATH . WPINC . '/widgets.php' );
    2619         add_action( '_admin_menu', 'wp_widgets_add_menu' );
    2620     }
     2617    if ( ! apply_filters('load_default_widgets', true) )
     2618        return;
     2619    require_once( ABSPATH . WPINC . '/default-widgets.php' );
     2620    add_action( '_admin_menu', 'wp_widgets_add_menu' );
    26212621}
    26222622
  • trunk/wp-includes/widgets.php

    r10794 r10795  
    394394
    395395/**
    396  * Register widget for sidebar with backwards compatibility.
    397  *
    398  * Allows $name to be an array that accepts either three elements to grab the
    399  * first element and the third for the name or just uses the first element of
    400  * the array for the name.
    401  *
    402  * Passes to {@link wp_register_sidebar_widget()} after argument list and
    403  * backwards compatibility is complete.
    404  *
    405  * @since 2.2.0
    406  * @uses wp_register_sidebar_widget() Passes the compiled arguments.
    407  *
    408  * @param string|int $name Widget ID.
    409  * @param callback $output_callback Run when widget is called.
    410  * @param string $classname Classname widget option.
    411  * @param mixed $params,... Widget parameters.
    412  */
    413 function register_sidebar_widget($name, $output_callback, $classname = '') {
    414     // Compat
    415     if ( is_array($name) ) {
    416         if ( count($name) == 3 )
    417             $name = sprintf($name[0], $name[2]);
    418         else
    419             $name = $name[0];
    420     }
    421 
    422     $id = sanitize_title($name);
    423     $options = array();
    424     if ( !empty($classname) && is_string($classname) )
    425         $options['classname'] = $classname;
    426     $params = array_slice(func_get_args(), 2);
    427     $args = array($id, $name, $output_callback, $options);
    428     if ( !empty($params) )
    429         $args = array_merge($args, $params);
    430 
    431     call_user_func_array('wp_register_sidebar_widget', $args);
    432 }
    433 
    434 /**
    435396 * Register widget for use in sidebars.
    436397 *
     
    499460
    500461/**
    501  * Alias of {@link wp_unregister_sidebar_widget()}.
    502  *
    503  * @see wp_unregister_sidebar_widget()
    504  *
    505  * @since 2.2.0
    506  *
    507  * @param int|string $id Widget ID.
    508  */
    509 function unregister_sidebar_widget($id) {
    510     return wp_unregister_sidebar_widget($id);
    511 }
    512 
    513 /**
    514462 * Remove widget from sidebar.
    515463 *
     
    521469    wp_register_sidebar_widget($id, '', '');
    522470    wp_unregister_widget_control($id);
    523 }
    524 
    525 /**
    526  * Registers widget control callback for customizing options.
    527  *
    528  * Allows $name to be an array that accepts either three elements to grab the
    529  * first element and the third for the name or just uses the first element of
    530  * the array for the name.
    531  *
    532  * Passes to {@link wp_register_widget_control()} after the argument list has
    533  * been compiled.
    534  *
    535  * @since 2.2.0
    536  *
    537  * @param int|string $name Sidebar ID.
    538  * @param callback $control_callback Widget control callback to display and process form.
    539  * @param int $width Widget width.
    540  * @param int $height Widget height.
    541  */
    542 function register_widget_control($name, $control_callback, $width = '', $height = '') {
    543     // Compat
    544     if ( is_array($name) ) {
    545         if ( count($name) == 3 )
    546             $name = sprintf($name[0], $name[2]);
    547         else
    548             $name = $name[0];
    549     }
    550 
    551     $id = sanitize_title($name);
    552     $options = array();
    553     if ( !empty($width) )
    554         $options['width'] = $width;
    555     if ( !empty($height) )
    556         $options['height'] = $height;
    557     $params = array_slice(func_get_args(), 4);
    558     $args = array($id, $name, $control_callback, $options);
    559     if ( !empty($params) )
    560         $args = array_merge($args, $params);
    561 
    562     call_user_func_array('wp_register_widget_control', $args);
    563471}
    564472
     
    608516
    609517    $wp_registered_widget_controls[$id] = $widget;
    610 }
    611 
    612 /**
    613  * Alias of {@link wp_unregister_widget_control()}.
    614  *
    615  * @since 2.2.0
    616  * @see wp_unregister_widget_control()
    617  *
    618  * @param int|string $id Widget ID.
    619  */
    620 function unregister_widget_control($id) {
    621     return wp_unregister_widget_control($id);
    622518}
    623519
     
    925821}
    926822
    927 /* Default Widgets */
    928 
    929 /**
    930  * Pages widget class
    931  *
    932  * @since 2.8.0
    933  */
    934 class WP_Widget_Pages extends WP_Widget {
    935 
    936     function WP_Widget_Pages() {
    937         $widget_ops = array('classname' => 'widget_pages', 'description' => __( "Your blog's WordPress Pages") );
    938         $this->WP_Widget('pages', __('Pages'), $widget_ops);
    939     }
    940 
    941     function widget( $args, $instance ) {
    942         extract( $args );
    943 
    944         $title = empty( $instance['title'] ) ? __( 'Pages' ) : apply_filters('widget_title', $instance['title']);
    945         $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
    946         $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    947 
    948         if ( $sortby == 'menu_order' )
    949             $sortby = 'menu_order, post_title';
    950 
    951         $out = wp_list_pages( array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) );
    952 
    953         if ( !empty( $out ) ) {
    954             echo $before_widget;
    955             echo $before_title . $title . $after_title;
    956         ?>
    957         <ul>
    958             <?php echo $out; ?>
    959         </ul>
    960         <?php
    961             echo $after_widget;
    962         }
    963     }
    964    
    965     function update( $new_instance, $old_instance ) {
    966         if ( !isset($new_instance['submit']) ) // user clicked cancel?
    967             return false;
    968 
    969         $instance = $old_instance;
    970         $instance['title'] = strip_tags($new_instance['title']);
    971         if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
    972             $instance['sortby'] = $new_instance['sortby'];
    973         } else {
    974             $instance['sortby'] = 'menu_order';
    975         }
    976 
    977         $instance['exclude'] = strip_tags( $new_instance['exclude'] );
    978 
    979         return $instance;
    980     }
    981    
    982     function form( $instance ) {
    983         //Defaults
    984         $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
    985         $title = attribute_escape( $instance['title'] );
    986         $exclude = attribute_escape( $instance['exclude'] );
    987     ?>
    988         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
    989         <p>
    990             <label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?>
    991                 <select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat">
    992                     <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
    993                     <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
    994                     <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
    995                 </select>
    996             </label>
    997         </p>
    998         <p>
    999             <label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude:' ); ?> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" /></label>
    1000             <br />
    1001             <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
    1002         </p>
    1003         <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
    1004 <?php
    1005     }
    1006 
    1007 }
    1008 
    1009 
    1010 /**
    1011  * Links widget class
    1012  *
    1013  * @since 2.8.0
    1014  */
    1015 class WP_Widget_Links extends WP_Widget {
    1016 
    1017     function WP_Widget_Links() {
    1018         $widget_ops = array('description' => __( "Your blogroll" ) );
    1019         $this->WP_Widget('links', __('Links'), $widget_ops);
    1020     }
    1021 
    1022     function widget( $args, $instance ) {
    1023         extract($args, EXTR_SKIP);
    1024 
    1025         $show_description = isset($instance['description']) ? $instance['description'] : false;
    1026         $show_name = isset($instance['name']) ? $instance['name'] : false;
    1027         $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
    1028         $show_images = isset($instance['images']) ? $instance['images'] : true;
    1029    
    1030         $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
    1031         wp_list_bookmarks(apply_filters('widget_links_args', array(
    1032             'title_before' => $before_title, 'title_after' => $after_title,
    1033             'category_before' => $before_widget, 'category_after' => $after_widget,
    1034             'show_images' => $show_images, 'show_description' => $show_description,
    1035             'show_name' => $show_name, 'show_rating' => $show_rating,
    1036             'class' => 'linkcat widget'
    1037         )));
    1038     }
    1039    
    1040     function update( $new_instance, $old_instance ) {
    1041         if( !isset($new_instance['submit']) ) // user clicked cancel?
    1042             return false;
    1043 
    1044         $new_instance = (array) $new_instance;
    1045         $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
    1046         foreach ( $instance as $field => $val ) {
    1047             if ( isset($new_instance[$field]) )
    1048                 $instance[$field] = 1;
    1049         }
    1050    
    1051         return $instance;
    1052     }
    1053    
    1054     function form( $instance ) {
    1055 
    1056         //Defaults
    1057         $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false) );
    1058 ?>
    1059         <p>
    1060         <label for="<?php echo $this->get_field_id('images'); ?>">
    1061         <input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" /> <?php _e('Show Link Image'); ?></label><br />
    1062         <label for="<?php echo $this->get_field_id('name'); ?>">
    1063         <input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" /> <?php _e('Show Link Name'); ?></label><br />
    1064         <label for="<?php echo $this->get_field_id('description'); ?>">
    1065         <input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" /> <?php _e('Show Link Description'); ?></label><br />
    1066         <label for="<?php echo $this->get_field_id('rating'); ?>">
    1067         <input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" /> <?php _e('Show Link Rating'); ?></label>
    1068         <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
    1069         </p>
    1070 <?php
    1071     }
    1072 }
    1073 
    1074 /**
    1075  * Search widget class
    1076  *
    1077  * @since 2.8.0
    1078  */
    1079 class WP_Widget_Search extends WP_Widget {
    1080 
    1081     function WP_Widget_Search() {
    1082         $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") );
    1083         $this->WP_Widget('search', __('Search'), $widget_ops);
    1084     }
    1085 
    1086     function widget( $args, $instance ) {
    1087         extract($args);
    1088         echo $before_widget;
    1089 
    1090         // Use current theme search form if it exists
    1091         get_search_form();
    1092 
    1093         echo $after_widget;
    1094     }
    1095 }
    1096 
    1097 /**
    1098  * Archives widget class
    1099  *
    1100  * @since 2.8.0
    1101  */
    1102 class WP_Widget_Archives extends WP_Widget {
    1103 
    1104     function WP_Widget_Archives() {
    1105         $widget_ops = array('classname' => 'widget_archive', 'description' => __( "A monthly archive of your blog's posts") );
    1106         $this->WP_Widget('archives', __('Archives'), $widget_ops);
    1107     }
    1108 
    1109     function widget( $args, $instance ) {
    1110         extract($args);
    1111         $c = $instance['count'] ? '1' : '0';
    1112         $d = $instance['dropdown'] ? '1' : '0';
    1113         $title = empty($instance['title']) ? __('Archives') : apply_filters('widget_title', $instance['title']);
    1114 
    1115         echo $before_widget;
    1116         echo $before_title . $title . $after_title;
    1117 
    1118         if ( $d ) {
    1119 ?>
    1120         <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=$c"); ?> </select>
    1121 <?php
    1122         } else {
    1123 ?>
    1124         <ul>
    1125         <?php wp_get_archives("type=monthly&show_post_count=$c"); ?>
    1126         </ul>
    1127 <?php
    1128         }
    1129 
    1130         echo $after_widget;
    1131     }
    1132 
    1133     function update( $new_instance, $old_instance ) {
    1134         if ( !isset($new_instance['submit']) ) // user clicked cancel?
    1135             return false;
    1136 
    1137         $instance = $old_instance;
    1138         $instance['title'] = strip_tags($new_instance['title']);
    1139         $instance['count'] = $new_instance['count'] ? 1 : 0;
    1140         $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
    1141 
    1142         return $instance;
    1143     }
    1144 
    1145     function form( $instance ) {
    1146         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
    1147         $title = strip_tags($instance['title']);
    1148         $count = $instance['count'] ? 'checked="checked"' : '';
    1149         $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
    1150 ?>
    1151         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
    1152         <p>
    1153             <label for="<?php echo $this->get_field_id('count'); ?>"><input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <?php _e('Show post counts'); ?></label>
    1154             <br />
    1155             <label for="<?php echo $this->get_field_id('dropdown'); ?>"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <?php _e('Display as a drop down'); ?></label>
    1156         </p>
    1157         <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
    1158 <?php
    1159     }
    1160 }
    1161 
    1162 /**
    1163  * Display meta widget.
    1164  *
    1165  * Displays log in/out, RSS feed links, etc.
    1166  *
    1167  * @since 2.2.0
    1168  *
    1169  * @param array $args Widget arguments.
    1170  */
    1171 function wp_widget_meta($args) {
    1172     extract($args);
    1173     $options = get_option('widget_meta');
    1174     $title = empty($options['title']) ? __('Meta') : apply_filters('widget_title', $options['title']);
    1175 ?>
    1176         <?php echo $before_widget; ?>
    1177             <?php echo $before_title . $title . $after_title; ?>
    1178             <ul>
    1179             <?php wp_register(); ?>
    1180             <li><?php wp_loginout(); ?></li>
    1181             <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo attribute_escape(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
    1182             <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo attribute_escape(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
    1183             <li><a href="http://wordpress.org/" title="<?php echo attribute_escape(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
    1184             <?php wp_meta(); ?>
    1185             </ul>
    1186         <?php echo $after_widget; ?>
    1187 <?php
    1188 }
    1189 
    1190 /**
    1191  * Display and process meta widget options form.
    1192  *
    1193  * @since 2.2.0
    1194  */
    1195 function wp_widget_meta_control() {
    1196     $options = $newoptions = get_option('widget_meta');
    1197     if ( isset($_POST["meta-submit"]) ) {
    1198         $newoptions['title'] = strip_tags(stripslashes($_POST["meta-title"]));
    1199     }
    1200     if ( $options != $newoptions ) {
    1201         $options = $newoptions;
    1202         update_option('widget_meta', $options);
    1203     }
    1204     $title = attribute_escape($options['title']);
    1205 ?>
    1206             <p><label for="meta-title"><?php _e('Title:'); ?> <input class="widefat" id="meta-title" name="meta-title" type="text" value="<?php echo $title; ?>" /></label></p>
    1207             <input type="hidden" id="meta-submit" name="meta-submit" value="1" />
    1208 <?php
    1209 }
    1210 
    1211 /**
    1212  * Display calendar widget.
    1213  *
    1214  * @since 2.2.0
    1215  *
    1216  * @param array $args Widget arguments.
    1217  */
    1218 function wp_widget_calendar($args) {
    1219     extract($args);
    1220     $options = get_option('widget_calendar');
    1221     $title = apply_filters('widget_title', $options['title']);
    1222     if ( empty($title) )
    1223         $title = '&nbsp;';
    1224     echo $before_widget . $before_title . $title . $after_title;
    1225     echo '<div id="calendar_wrap">';
    1226     get_calendar();
    1227     echo '</div>';
    1228     echo $after_widget;
    1229 }
    1230 
    1231 /**
    1232  * Display and process calendar widget options form.
    1233  *
    1234  * @since 2.2.0
    1235  */
    1236 function wp_widget_calendar_control() {
    1237     $options = $newoptions = get_option('widget_calendar');
    1238     if ( isset($_POST["calendar-submit"]) ) {
    1239         $newoptions['title'] = strip_tags(stripslashes($_POST["calendar-title"]));
    1240     }
    1241     if ( $options != $newoptions ) {
    1242         $options = $newoptions;
    1243         update_option('widget_calendar', $options);
    1244     }
    1245     $title = attribute_escape($options['title']);
    1246 ?>
    1247             <p><label for="calendar-title"><?php _e('Title:'); ?> <input class="widefat" id="calendar-title" name="calendar-title" type="text" value="<?php echo $title; ?>" /></label></p>
    1248             <input type="hidden" id="calendar-submit" name="calendar-submit" value="1" />
    1249 <?php
    1250 }
    1251 
    1252 /**
    1253  * Display the Text widget, depending on the widget number.
    1254  *
    1255  * Supports multiple text widgets and keeps track of the widget number by using
    1256  * the $widget_args parameter. The option 'widget_text' is used to store the
    1257  * content for the widgets. The content and title are passed through the
    1258  * 'widget_text' and 'widget_title' filters respectively.
    1259  *
    1260  * @since 2.2.0
    1261  *
    1262  * @param array $args Widget arguments.
    1263  * @param int $number Widget number.
    1264  */
    1265 function wp_widget_text($args, $widget_args = 1) {
    1266     extract( $args, EXTR_SKIP );
    1267     if ( is_numeric($widget_args) )
    1268         $widget_args = array( 'number' => $widget_args );
    1269     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    1270     extract( $widget_args, EXTR_SKIP );
    1271 
    1272     $options = get_option('widget_text');
    1273     if ( !isset($options[$number]) )
    1274         return;
    1275 
    1276     $title = apply_filters('widget_title', $options[$number]['title']);
    1277     $text = apply_filters( 'widget_text', $options[$number]['text'] );
    1278 ?>
    1279         <?php echo $before_widget; ?>
    1280             <?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
    1281             <div class="textwidget"><?php echo $text; ?></div>
    1282         <?php echo $after_widget; ?>
    1283 <?php
    1284 }
    1285 
    1286 /**
    1287  * Display and process text widget options form.
    1288  *
    1289  * @since 2.2.0
    1290  *
    1291  * @param int $widget_args Widget number.
    1292  */
    1293 function wp_widget_text_control($widget_args) {
    1294     global $wp_registered_widgets;
    1295     static $updated = false;
    1296 
    1297     if ( is_numeric($widget_args) )
    1298         $widget_args = array( 'number' => $widget_args );
    1299     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    1300     extract( $widget_args, EXTR_SKIP );
    1301 
    1302     $options = get_option('widget_text');
    1303     if ( !is_array($options) )
    1304         $options = array();
    1305 
    1306     if ( !$updated && !empty($_POST['sidebar']) ) {
    1307         $sidebar = (string) $_POST['sidebar'];
    1308 
    1309         $sidebars_widgets = wp_get_sidebars_widgets();
    1310         if ( isset($sidebars_widgets[$sidebar]) )
    1311             $this_sidebar =& $sidebars_widgets[$sidebar];
     823/**
     824 * Deprecated API
     825 */
     826 
     827/**
     828 * Register widget for sidebar with backwards compatibility.
     829 *
     830 * Allows $name to be an array that accepts either three elements to grab the
     831 * first element and the third for the name or just uses the first element of
     832 * the array for the name.
     833 *
     834 * Passes to {@link wp_register_sidebar_widget()} after argument list and
     835 * backwards compatibility is complete.
     836 *
     837 * @since 2.2.0
     838 * @uses wp_register_sidebar_widget() Passes the compiled arguments.
     839 *
     840 * @param string|int $name Widget ID.
     841 * @param callback $output_callback Run when widget is called.
     842 * @param string $classname Classname widget option.
     843 * @param mixed $params,... Widget parameters.
     844 */
     845function register_sidebar_widget($name, $output_callback, $classname = '') {
     846    // Compat
     847    if ( is_array($name) ) {
     848        if ( count($name) == 3 )
     849            $name = sprintf($name[0], $name[2]);
    1312850        else
    1313             $this_sidebar = array();
    1314 
    1315         foreach ( (array) $this_sidebar as $_widget_id ) {
    1316             if ( 'wp_widget_text' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    1317                 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
    1318                 if ( !in_array( "text-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
    1319                     unset($options[$widget_number]);
    1320             }
    1321         }
    1322 
    1323         foreach ( (array) $_POST['widget-text'] as $widget_number => $widget_text ) {
    1324             if ( !isset($widget_text['text']) && isset($options[$widget_number]) ) // user clicked cancel
    1325                 continue;
    1326             $title = strip_tags(stripslashes($widget_text['title']));
    1327             if ( current_user_can('unfiltered_html') )
    1328                 $text = stripslashes( $widget_text['text'] );
    1329             else
    1330                 $text = stripslashes(wp_filter_post_kses( $widget_text['text'] ));
    1331             $options[$widget_number] = compact( 'title', 'text' );
    1332         }
    1333 
    1334         update_option('widget_text', $options);
    1335         $updated = true;
    1336     }
    1337 
    1338     if ( -1 == $number ) {
    1339         $title = '';
    1340         $text = '';
    1341         $number = '%i%';
    1342     } else {
    1343         $title = attribute_escape($options[$number]['title']);
    1344         $text = format_to_edit($options[$number]['text']);
    1345     }
    1346 ?>
    1347         <p>
    1348             <input class="widefat" id="text-title-<?php echo $number; ?>" name="widget-text[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
    1349             <textarea class="widefat" rows="16" cols="20" id="text-text-<?php echo $number; ?>" name="widget-text[<?php echo $number; ?>][text]"><?php echo $text; ?></textarea>
    1350             <input type="hidden" name="widget-text[<?php echo $number; ?>][submit]" value="1" />
    1351         </p>
    1352 <?php
    1353 }
    1354 
    1355 /**
    1356  * Register text widget on startup.
    1357  *
    1358  * @since 2.2.0
    1359  */
    1360 function wp_widget_text_register() {
    1361     $options = get_option('widget_text');
    1362     if ( !is_array($options) )
    1363         $options = array();
    1364 
    1365     $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
    1366     $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'text');
    1367     $name = __('Text');
    1368 
    1369     $id = false;
    1370     foreach ( (array) array_keys($options) as $o ) {
    1371         // Old widgets can have null values for some reason
    1372         if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) )
    1373             continue;
    1374         $id = "text-$o"; // Never never never translate an id
    1375         wp_register_sidebar_widget($id, $name, 'wp_widget_text', $widget_ops, array( 'number' => $o ));
    1376         wp_register_widget_control($id, $name, 'wp_widget_text_control', $control_ops, array( 'number' => $o ));
    1377     }
    1378 
    1379     // If there are none, we register the widget's existance with a generic template
    1380     if ( !$id ) {
    1381         wp_register_sidebar_widget( 'text-1', $name, 'wp_widget_text', $widget_ops, array( 'number' => -1 ) );
    1382         wp_register_widget_control( 'text-1', $name, 'wp_widget_text_control', $control_ops, array( 'number' => -1 ) );
    1383     }
    1384 }
    1385 
    1386 /**
    1387  * Display categories widget.
    1388  *
    1389  * Allows multiple category widgets.
    1390  *
    1391  * @since 2.2.0
    1392  *
    1393  * @param array $args Widget arguments.
    1394  * @param int $number Widget number.
    1395  */
    1396 function wp_widget_categories($args, $widget_args = 1) {
    1397     extract($args, EXTR_SKIP);
    1398     if ( is_numeric($widget_args) )
    1399         $widget_args = array( 'number' => $widget_args );
    1400     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    1401     extract($widget_args, EXTR_SKIP);
    1402 
    1403     $options = get_option('widget_categories');
    1404     if ( !isset($options[$number]) )
    1405         return;
    1406 
    1407     $c = $options[$number]['count'] ? '1' : '0';
    1408     $h = $options[$number]['hierarchical'] ? '1' : '0';
    1409     $d = $options[$number]['dropdown'] ? '1' : '0';
    1410 
    1411     $title = empty($options[$number]['title']) ? __('Categories') : apply_filters('widget_title', $options[$number]['title']);
    1412 
    1413     echo $before_widget;
    1414     echo $before_title . $title . $after_title;
    1415 
    1416     $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
    1417 
    1418     if ( $d ) {
    1419         $cat_args['show_option_none'] = __('Select Category');
    1420         wp_dropdown_categories($cat_args);
    1421 ?>
    1422 
    1423 <script type='text/javascript'>
    1424 /* <![CDATA[ */
    1425     var dropdown = document.getElementById("cat");
    1426     function onCatChange() {
    1427         if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    1428             location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
    1429         }
    1430     }
    1431     dropdown.onchange = onCatChange;
    1432 /* ]]> */
    1433 </script>
    1434 
    1435 <?php
    1436     } else {
    1437 ?>
    1438         <ul>
    1439         <?php
    1440             $cat_args['title_li'] = '';
    1441             wp_list_categories($cat_args);
    1442         ?>
    1443         </ul>
    1444 <?php
    1445     }
    1446 
    1447     echo $after_widget;
    1448 }
    1449 
    1450 /**
    1451  * Display and process categories widget options form.
    1452  *
    1453  * @since 2.2.0
    1454  *
    1455  * @param int $widget_args Widget number.
    1456  */
    1457 function wp_widget_categories_control( $widget_args ) {
    1458     global $wp_registered_widgets;
    1459     static $updated = false;
    1460 
    1461     if ( is_numeric($widget_args) )
    1462         $widget_args = array( 'number' => $widget_args );
    1463     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    1464     extract($widget_args, EXTR_SKIP);
    1465 
    1466     $options = get_option('widget_categories');
    1467 
    1468     if ( !is_array( $options ) )
    1469         $options = array();
    1470 
    1471     if ( !$updated && !empty($_POST['sidebar']) ) {
    1472         $sidebar = (string) $_POST['sidebar'];
    1473 
    1474         $sidebars_widgets = wp_get_sidebars_widgets();
    1475         if ( isset($sidebars_widgets[$sidebar]) )
    1476             $this_sidebar =& $sidebars_widgets[$sidebar];
     851            $name = $name[0];
     852    }
     853
     854    $id = sanitize_title($name);
     855    $options = array();
     856    if ( !empty($classname) && is_string($classname) )
     857        $options['classname'] = $classname;
     858    $params = array_slice(func_get_args(), 2);
     859    $args = array($id, $name, $output_callback, $options);
     860    if ( !empty($params) )
     861        $args = array_merge($args, $params);
     862
     863    call_user_func_array('wp_register_sidebar_widget', $args);
     864}
     865
     866/**
     867 * Alias of {@link wp_unregister_sidebar_widget()}.
     868 *
     869 * @see wp_unregister_sidebar_widget()
     870 *
     871 * @since 2.2.0
     872 *
     873 * @param int|string $id Widget ID.
     874 */
     875function unregister_sidebar_widget($id) {
     876    return wp_unregister_sidebar_widget($id);
     877}
     878
     879/**
     880 * Registers widget control callback for customizing options.
     881 *
     882 * Allows $name to be an array that accepts either three elements to grab the
     883 * first element and the third for the name or just uses the first element of
     884 * the array for the name.
     885 *
     886 * Passes to {@link wp_register_widget_control()} after the argument list has
     887 * been compiled.
     888 *
     889 * @since 2.2.0
     890 *
     891 * @param int|string $name Sidebar ID.
     892 * @param callback $control_callback Widget control callback to display and process form.
     893 * @param int $width Widget width.
     894 * @param int $height Widget height.
     895 */
     896function register_widget_control($name, $control_callback, $width = '', $height = '') {
     897    // Compat
     898    if ( is_array($name) ) {
     899        if ( count($name) == 3 )
     900            $name = sprintf($name[0], $name[2]);
    1477901        else
    1478             $this_sidebar = array();
    1479 
    1480         foreach ( (array) $this_sidebar as $_widget_id ) {
    1481             if ( 'wp_widget_categories' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    1482                 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
    1483                 if ( !in_array( "categories-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
    1484                     unset($options[$widget_number]);
    1485             }
    1486         }
    1487 
    1488         foreach ( (array) $_POST['widget-categories'] as $widget_number => $widget_cat ) {
    1489             if ( !isset($widget_cat['title']) && isset($options[$widget_number]) ) // user clicked cancel
    1490                 continue;
    1491             $title = trim(strip_tags(stripslashes($widget_cat['title'])));
    1492             $count = isset($widget_cat['count']);
    1493             $hierarchical = isset($widget_cat['hierarchical']);
    1494             $dropdown = isset($widget_cat['dropdown']);
    1495             $options[$widget_number] = compact( 'title', 'count', 'hierarchical', 'dropdown' );
    1496         }
    1497 
    1498         update_option('widget_categories', $options);
    1499         $updated = true;
    1500     }
    1501 
    1502     if ( -1 == $number ) {
    1503         $title = '';
    1504         $count = false;
    1505         $hierarchical = false;
    1506         $dropdown = false;
    1507         $number = '%i%';
    1508     } else {
    1509         $title = attribute_escape( $options[$number]['title'] );
    1510         $count = (bool) $options[$number]['count'];
    1511         $hierarchical = (bool) $options[$number]['hierarchical'];
    1512         $dropdown = (bool) $options[$number]['dropdown'];
    1513     }
    1514 ?>
    1515             <p>
    1516                 <label for="categories-title-<?php echo $number; ?>">
    1517                     <?php _e( 'Title:' ); ?>
    1518                     <input class="widefat" id="categories-title-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
    1519                 </label>
    1520             </p>
    1521 
    1522             <p>
    1523                 <label for="categories-dropdown-<?php echo $number; ?>">
    1524                     <input type="checkbox" class="checkbox" id="categories-dropdown-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][dropdown]"<?php checked( $dropdown ); ?> />
    1525                     <?php _e( 'Show as dropdown' ); ?>
    1526                 </label>
    1527                 <br />
    1528                 <label for="categories-count-<?php echo $number; ?>">
    1529                     <input type="checkbox" class="checkbox" id="categories-count-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][count]"<?php checked( $count ); ?> />
    1530                     <?php _e( 'Show post counts' ); ?>
    1531                 </label>
    1532                 <br />
    1533                 <label for="categories-hierarchical-<?php echo $number; ?>">
    1534                     <input type="checkbox" class="checkbox" id="categories-hierarchical-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][hierarchical]"<?php checked( $hierarchical ); ?> />
    1535                     <?php _e( 'Show hierarchy' ); ?>
    1536                 </label>
    1537             </p>
    1538 
    1539             <input type="hidden" name="widget-categories[<?php echo $number; ?>][submit]" value="1" />
    1540 <?php
    1541 }
    1542 
    1543 /**
    1544  * Register categories widget on startup.
    1545  *
    1546  * @since 2.3.0
    1547  */
    1548 function wp_widget_categories_register() {
    1549     if ( !$options = get_option( 'widget_categories' ) )
    1550         $options = array();
    1551 
    1552     if ( isset($options['title']) )
    1553         $options = wp_widget_categories_upgrade();
    1554 
    1555     $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
    1556 
    1557     $name = __( 'Categories' );
    1558 
    1559     $id = false;
    1560     foreach ( (array) array_keys($options) as $o ) {
    1561         // Old widgets can have null values for some reason
    1562         if ( !isset($options[$o]['title']) )
    1563             continue;
    1564         $id = "categories-$o";
    1565         wp_register_sidebar_widget( $id, $name, 'wp_widget_categories', $widget_ops, array( 'number' => $o ) );
    1566         wp_register_widget_control( $id, $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => $o ) );
    1567     }
    1568 
    1569     // If there are none, we register the widget's existance with a generic template
    1570     if ( !$id ) {
    1571         wp_register_sidebar_widget( 'categories-1', $name, 'wp_widget_categories', $widget_ops, array( 'number' => -1 ) );
    1572         wp_register_widget_control( 'categories-1', $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => -1 ) );
    1573     }
    1574 }
    1575 
    1576 /**
    1577  * Upgrade previous category widget to current version.
    1578  *
    1579  * @since 2.3.0
    1580  *
    1581  * @return array
    1582  */
    1583 function wp_widget_categories_upgrade() {
    1584     $options = get_option( 'widget_categories' );
    1585 
    1586     if ( !isset( $options['title'] ) )
    1587         return $options;
    1588 
    1589     $newoptions = array( 1 => $options );
    1590 
    1591     update_option( 'widget_categories', $newoptions );
    1592 
    1593     $sidebars_widgets = get_option( 'sidebars_widgets' );
    1594     if ( is_array( $sidebars_widgets ) ) {
    1595         foreach ( $sidebars_widgets as $sidebar => $widgets ) {
    1596             if ( is_array( $widgets ) ) {
    1597                 foreach ( $widgets as $widget )
    1598                     $new_widgets[$sidebar][] = ( $widget == 'categories' ) ? 'categories-1' : $widget;
    1599             } else {
    1600                 $new_widgets[$sidebar] = $widgets;
    1601             }
    1602         }
    1603         if ( $new_widgets != $sidebars_widgets )
    1604             update_option( 'sidebars_widgets', $new_widgets );
    1605     }
    1606 
    1607     return $newoptions;
    1608 }
    1609 
    1610 /**
    1611  * Display recent entries widget.
    1612  *
    1613  * @since 2.2.0
    1614  *
    1615  * @param array $args Widget arguments.
    1616  * @return int Displayed cache.
    1617  */
    1618 function wp_widget_recent_entries($args) {
    1619     if ( '%BEG_OF_TITLE%' != $args['before_title'] ) {
    1620         if ( $output = wp_cache_get('widget_recent_entries', 'widget') )
    1621             return print($output);
    1622         ob_start();
    1623     }
    1624 
    1625     extract($args);
    1626     $options = get_option('widget_recent_entries');
    1627     $title = empty($options['title']) ? __('Recent Posts') : apply_filters('widget_title', $options['title']);
    1628     if ( !$number = (int) $options['number'] )
    1629         $number = 10;
    1630     else if ( $number < 1 )
    1631         $number = 1;
    1632     else if ( $number > 15 )
    1633         $number = 15;
    1634 
    1635     $r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
    1636     if ($r->have_posts()) :
    1637 ?>
    1638         <?php echo $before_widget; ?>
    1639             <?php echo $before_title . $title . $after_title; ?>
    1640             <ul>
    1641             <?php  while ($r->have_posts()) : $r->the_post(); ?>
    1642             <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
    1643             <?php endwhile; ?>
    1644             </ul>
    1645         <?php echo $after_widget; ?>
    1646 <?php
    1647         wp_reset_query();  // Restore global post data stomped by the_post().
    1648     endif;
    1649 
    1650     if ( '%BEG_OF_TITLE%' != $args['before_title'] )
    1651         wp_cache_add('widget_recent_entries', ob_get_flush(), 'widget');
    1652 }
    1653 
    1654 /**
    1655  * Remove recent entries widget items cache.
    1656  *
    1657  * @since 2.2.0
    1658  */
    1659 function wp_flush_widget_recent_entries() {
    1660     wp_cache_delete('widget_recent_entries', 'widget');
    1661 }
    1662 
    1663 add_action('save_post', 'wp_flush_widget_recent_entries');
    1664 add_action('deleted_post', 'wp_flush_widget_recent_entries');
    1665 add_action('switch_theme', 'wp_flush_widget_recent_entries');
    1666 
    1667 /**
    1668  * Display and process recent entries widget options form.
    1669  *
    1670  * @since 2.2.0
    1671  */
    1672 function wp_widget_recent_entries_control() {
    1673     $options = $newoptions = get_option('widget_recent_entries');
    1674     if ( isset($_POST["recent-entries-submit"]) ) {
    1675         $newoptions['title'] = strip_tags(stripslashes($_POST["recent-entries-title"]));
    1676         $newoptions['number'] = (int) $_POST["recent-entries-number"];
    1677     }
    1678     if ( $options != $newoptions ) {
    1679         $options = $newoptions;
    1680         update_option('widget_recent_entries', $options);
    1681         wp_flush_widget_recent_entries();
    1682     }
    1683     $title = attribute_escape($options['title']);
    1684     if ( !$number = (int) $options['number'] )
    1685         $number = 5;
    1686 ?>
    1687 
    1688             <p><label for="recent-entries-title"><?php _e('Title:'); ?> <input class="widefat" id="recent-entries-title" name="recent-entries-title" type="text" value="<?php echo $title; ?>" /></label></p>
    1689             <p>
    1690                 <label for="recent-entries-number"><?php _e('Number of posts to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-entries-number" name="recent-entries-number" type="text" value="<?php echo $number; ?>" /></label>
    1691                 <br />
    1692                 <small><?php _e('(at most 15)'); ?></small>
    1693             </p>
    1694             <input type="hidden" id="recent-entries-submit" name="recent-entries-submit" value="1" />
    1695 <?php
    1696 }
    1697 
    1698 /**
    1699  * Display recent comments widget.
    1700  *
    1701  * @since 2.2.0
    1702  *
    1703  * @param array $args Widget arguments.
    1704  */
    1705 function wp_widget_recent_comments($args) {
    1706     global $wpdb, $comments, $comment;
    1707     extract($args, EXTR_SKIP);
    1708     $options = get_option('widget_recent_comments');
    1709     $title = empty($options['title']) ? __('Recent Comments') : apply_filters('widget_title', $options['title']);
    1710     if ( !$number = (int) $options['number'] )
    1711         $number = 5;
    1712     else if ( $number < 1 )
    1713         $number = 1;
    1714     else if ( $number > 15 )
    1715         $number = 15;
    1716 
    1717     if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
    1718         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
    1719         wp_cache_add( 'recent_comments', $comments, 'widget' );
    1720     }
    1721 ?>
    1722 
    1723         <?php echo $before_widget; ?>
    1724             <?php echo $before_title . $title . $after_title; ?>
    1725             <ul id="recentcomments"><?php
    1726             if ( $comments ) : foreach ( (array) $comments as $comment) :
    1727             echo  '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . clean_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
    1728             endforeach; endif;?></ul>
    1729         <?php echo $after_widget; ?>
    1730 <?php
    1731 }
    1732 
    1733 /**
    1734  * Remove the cache for recent comments widget.
    1735  *
    1736  * @since 2.2.0
    1737  */
    1738 function wp_delete_recent_comments_cache() {
    1739     wp_cache_delete( 'recent_comments', 'widget' );
    1740 }
    1741 add_action( 'comment_post', 'wp_delete_recent_comments_cache' );
    1742 add_action( 'wp_set_comment_status', 'wp_delete_recent_comments_cache' );
    1743 
    1744 /**
    1745  * Display and process recent comments widget options form.
    1746  *
    1747  * @since 2.2.0
    1748  */
    1749 function wp_widget_recent_comments_control() {
    1750     $options = $newoptions = get_option('widget_recent_comments');
    1751     if ( isset($_POST["recent-comments-submit"]) ) {
    1752         $newoptions['title'] = strip_tags(stripslashes($_POST["recent-comments-title"]));
    1753         $newoptions['number'] = (int) $_POST["recent-comments-number"];
    1754     }
    1755     if ( $options != $newoptions ) {
    1756         $options = $newoptions;
    1757         update_option('widget_recent_comments', $options);
    1758         wp_delete_recent_comments_cache();
    1759     }
    1760     $title = attribute_escape($options['title']);
    1761     if ( !$number = (int) $options['number'] )
    1762         $number = 5;
    1763 ?>
    1764             <p><label for="recent-comments-title"><?php _e('Title:'); ?> <input class="widefat" id="recent-comments-title" name="recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p>
    1765             <p>
    1766                 <label for="recent-comments-number"><?php _e('Number of comments to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-comments-number" name="recent-comments-number" type="text" value="<?php echo $number; ?>" /></label>
    1767                 <br />
    1768                 <small><?php _e('(at most 15)'); ?></small>
    1769             </p>
    1770             <input type="hidden" id="recent-comments-submit" name="recent-comments-submit" value="1" />
    1771 <?php
    1772 }
    1773 
    1774 /**
    1775  * Display the style for recent comments widget.
    1776  *
    1777  * @since 2.2.0
    1778  */
    1779 function wp_widget_recent_comments_style() {
    1780 ?>
    1781 <style type="text/css">.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}</style>
    1782 <?php
    1783 }
    1784 
    1785 /**
    1786  * Register recent comments with control and hook for 'wp_head' action.
    1787  *
    1788  * @since 2.2.0
    1789  */
    1790 function wp_widget_recent_comments_register() {
    1791     $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
    1792     wp_register_sidebar_widget('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments', $widget_ops);
    1793     wp_register_widget_control('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments_control');
    1794 
    1795     if ( is_active_widget('wp_widget_recent_comments') )
    1796         add_action('wp_head', 'wp_widget_recent_comments_style');
    1797 }
    1798 
    1799 /**
    1800  * Display RSS widget.
    1801  *
    1802  * Allows for multiple widgets to be displayed.
    1803  *
    1804  * @since 2.2.0
    1805  *
    1806  * @param array $args Widget arguments.
    1807  * @param int $number Widget number.
    1808  */
    1809 function wp_widget_rss($args, $widget_args = 1) {
    1810     extract($args, EXTR_SKIP);
    1811     if ( is_numeric($widget_args) )
    1812         $widget_args = array( 'number' => $widget_args );
    1813     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    1814     extract($widget_args, EXTR_SKIP);
    1815 
    1816     $options = get_option('widget_rss');
    1817 
    1818     if ( !isset($options[$number]) )
    1819         return;
    1820 
    1821     if ( isset($options[$number]['error']) && $options[$number]['error'] )
    1822         return;
    1823 
    1824     $url = $options[$number]['url'];
    1825     while ( stristr($url, 'http') != $url )
    1826         $url = substr($url, 1);
    1827     if ( empty($url) )
    1828         return;
    1829 
    1830     $rss = fetch_feed($url);
    1831     $title = $options[$number]['title'];
    1832     $desc = '';
    1833     $link = '';
    1834     if ( ! is_wp_error($rss) ) {
    1835         $desc = attribute_escape(strip_tags(html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
    1836         if ( empty($title) )
    1837             $title = htmlentities(strip_tags($rss->get_title()));
    1838         $link = clean_url(strip_tags($rss->get_permalink()));
    1839         while ( stristr($link, 'http') != $link )
    1840             $link = substr($link, 1);
    1841     }
    1842     if ( empty($title) )
    1843         $title = $desc;
    1844     if ( empty($title) )
    1845         $title = __('Unknown Feed');
    1846     $title = apply_filters('widget_title', $title );
    1847     $url = clean_url(strip_tags($url));
    1848     $icon = includes_url('images/rss.png');
    1849     $title = "<a class='rsswidget' href='$url' title='" . attribute_escape(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
    1850 
    1851     echo $before_widget;
    1852     echo $before_title . $title . $after_title;
    1853 
    1854     wp_widget_rss_output( $rss, $options[$number] );
    1855 
    1856     echo $after_widget;
    1857 }
    1858 
    1859 /**
    1860  * Display the RSS entries in a list.
    1861  *
    1862  * @since 2.5.0
    1863  *
    1864  * @param string|array|object $rss RSS url.
    1865  * @param array $args Widget arguments.
    1866  */
    1867 function wp_widget_rss_output( $rss, $args = array() ) {
    1868     if ( is_string( $rss ) ) {
    1869         $rss = fetch_feed($rss);
    1870     } elseif ( is_array($rss) && isset($rss['url']) ) {
    1871         $args = $rss;
    1872         $rss = fetch_feed($rss['url']);
    1873     } elseif ( !is_object($rss) ) {
    1874         return;
    1875     }
    1876 
    1877     if ( is_wp_error($rss) ) {
    1878         if ( is_admin() || current_user_can('manage_options') ) {
    1879             echo '<p>';
    1880             printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
    1881             echo '</p>';
    1882         }
    1883         return;
    1884     }
    1885 
    1886     $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
    1887     $args = wp_parse_args( $args, $default_args );
    1888     extract( $args, EXTR_SKIP );
    1889 
    1890     $items = (int) $items;
    1891     if ( $items < 1 || 20 < $items )
    1892         $items = 10;
    1893     $show_summary  = (int) $show_summary;
    1894     $show_author   = (int) $show_author;
    1895     $show_date     = (int) $show_date;
    1896 
    1897     if ( !$rss->get_item_quantity() ) {
    1898         echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
    1899         return;
    1900     }
    1901 
    1902     echo '<ul>';
    1903     foreach ( $rss->get_items(0, $items) as $item ) {
    1904         $link = $item->get_link();
    1905         while ( stristr($link, 'http') != $link )
    1906             $link = substr($link, 1);
    1907         $link = clean_url(strip_tags($link));
    1908         $title = attribute_escape(strip_tags($item->get_title()));
    1909         if ( empty($title) )
    1910             $title = __('Untitled');
    1911 
    1912         $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset')))));
    1913         $desc = wp_html_excerpt( $desc, 360 ) . ' [&hellip;]';
    1914         $desc = wp_specialchars( $desc );
    1915 
    1916         if ( $show_summary ) {
    1917             $summary = "<div class='rssSummary'>$desc</div>";
    1918         } else {
    1919             $summary = '';
    1920         }
    1921 
    1922         $date = '';
    1923         if ( $show_date ) {
    1924             $date = $item->get_date();
    1925 
    1926             if ( $date ) {
    1927                 if ( $date_stamp = strtotime( $date ) )
    1928                     $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>';
    1929                 else
    1930                     $date = '';
    1931             }
    1932         }
    1933 
    1934         $author = '';
    1935         if ( $show_author ) {
    1936             $author = $item->get_author();
    1937             $author = $author->get_name();
    1938             $author = ' <cite>' . wp_specialchars( strip_tags( $author ) ) . '</cite>';
    1939         }
    1940 
    1941         if ( $link == '' ) {
    1942             echo "<li>$title{$date}{$summary}{$author}</li>";
    1943         } else {
    1944             echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
    1945         }
    1946     }
    1947     echo '</ul>';
    1948 }
    1949 
    1950 /**
    1951  * Display and process RSS widget control form.
    1952  *
    1953  * @since 2.2.0
    1954  *
    1955  * @param int $widget_args Widget number.
    1956  */
    1957 function wp_widget_rss_control($widget_args) {
    1958     global $wp_registered_widgets;
    1959     static $updated = false;
    1960 
    1961     if ( is_numeric($widget_args) )
    1962         $widget_args = array( 'number' => $widget_args );
    1963     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    1964     extract($widget_args, EXTR_SKIP);
    1965 
    1966     $options = get_option('widget_rss');
    1967     if ( !is_array($options) )
    1968         $options = array();
    1969 
    1970     $urls = array();
    1971     foreach ( (array) $options as $option )
    1972         if ( isset($option['url']) )
    1973             $urls[$option['url']] = true;
    1974 
    1975     if ( !$updated && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['sidebar']) ) {
    1976         $sidebar = (string) $_POST['sidebar'];
    1977 
    1978         $sidebars_widgets = wp_get_sidebars_widgets();
    1979         if ( isset($sidebars_widgets[$sidebar]) )
    1980             $this_sidebar =& $sidebars_widgets[$sidebar];
    1981         else
    1982             $this_sidebar = array();
    1983 
    1984         foreach ( (array) $this_sidebar as $_widget_id ) {
    1985             if ( 'wp_widget_rss' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    1986                 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
    1987                 if ( !in_array( "rss-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
    1988                     unset($options[$widget_number]);
    1989             }
    1990         }
    1991 
    1992         foreach( (array) $_POST['widget-rss'] as $widget_number => $widget_rss ) {
    1993             if ( !isset($widget_rss['url']) && isset($options[$widget_number]) ) // user clicked cancel
    1994                 continue;
    1995             $widget_rss = stripslashes_deep( $widget_rss );
    1996             $url = sanitize_url(strip_tags($widget_rss['url']));
    1997             $options[$widget_number] = wp_widget_rss_process( $widget_rss, !isset($urls[$url]) );
    1998         }
    1999 
    2000         update_option('widget_rss', $options);
    2001         $updated = true;
    2002     }
    2003 
    2004     if ( -1 == $number ) {
    2005         $title = '';
    2006         $url = '';
    2007         $items = 10;
    2008         $error = false;
    2009         $number = '%i%';
    2010         $show_summary = 0;
    2011         $show_author = 0;
    2012         $show_date = 0;
    2013     } else {
    2014         extract( (array) $options[$number] );
    2015     }
    2016 
    2017     wp_widget_rss_form( compact( 'number', 'title', 'url', 'items', 'error', 'show_summary', 'show_author', 'show_date' ) );
    2018 }
    2019 
    2020 /**
    2021  * Display RSS widget options form.
    2022  *
    2023  * The options for what fields are displayed for the RSS form are all booleans
    2024  * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
    2025  * 'show_date'.
    2026  *
    2027  * @since 2.5.0
    2028  *
    2029  * @param array|string $args Values for input fields.
    2030  * @param array $inputs Override default display options.
    2031  */
    2032 function wp_widget_rss_form( $args, $inputs = null ) {
    2033 
    2034     $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
    2035     $inputs = wp_parse_args( $inputs, $default_inputs );
    2036     extract( $args );
    2037     extract( $inputs, EXTR_SKIP);
    2038 
    2039     $number = attribute_escape( $number );
    2040     $title  = attribute_escape( $title );
    2041     $url    = attribute_escape( $url );
    2042     $items  = (int) $items;
    2043     if ( $items < 1 || 20 < $items )
    2044         $items  = 10;
    2045     $show_summary   = (int) $show_summary;
    2046     $show_author    = (int) $show_author;
    2047     $show_date      = (int) $show_date;
    2048 
    2049     if ( !empty($error) ) {
    2050         $message = sprintf( __('Error in RSS Widget: %s'), $error);
    2051         echo "<div class='error'><p>$message</p></div>";
    2052         echo "<p class='hide-if-no-js'><strong>$message</strong></p>";
    2053     }
    2054 
    2055     if ( $inputs['url'] ) :
    2056 ?>
    2057     <p>
    2058         <label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?>
    2059             <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" />
    2060         </label>
    2061     </p>
    2062 <?php endif; if ( $inputs['title'] ) : ?>
    2063     <p>
    2064         <label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?>
    2065             <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
    2066         </label>
    2067     </p>
    2068 <?php endif; if ( $inputs['items'] ) : ?>
    2069     <p>
    2070         <label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?>
    2071             <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
    2072                 <?php
    2073                     for ( $i = 1; $i <= 20; ++$i )
    2074                         echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
    2075                 ?>
    2076             </select>
    2077         </label>
    2078     </p>
    2079 <?php endif; if ( $inputs['show_summary'] ) : ?>
    2080     <p>
    2081         <label for="rss-show-summary-<?php echo $number; ?>">
    2082             <input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>
    2083             <?php _e('Display item content?'); ?>
    2084         </label>
    2085     </p>
    2086 <?php endif; if ( $inputs['show_author'] ) : ?>
    2087     <p>
    2088         <label for="rss-show-author-<?php echo $number; ?>">
    2089             <input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>
    2090             <?php _e('Display item author if available?'); ?>
    2091         </label>
    2092     </p>
    2093 <?php endif; if ( $inputs['show_date'] ) : ?>
    2094     <p>
    2095         <label for="rss-show-date-<?php echo $number; ?>">
    2096             <input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>
    2097             <?php _e('Display item date?'); ?>
    2098         </label>
    2099     </p>
    2100     <input type="hidden" name="widget-rss[<?php echo $number; ?>][submit]" value="1" />
    2101 <?php
    2102     endif;
    2103     foreach ( array_keys($default_inputs) as $input ) :
    2104         if ( 'hidden' === $inputs[$input] ) :
    2105             $id = str_replace( '_', '-', $input );
    2106 ?>
    2107     <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
    2108 <?php
    2109         endif;
    2110     endforeach;
    2111 }
    2112 
    2113 /**
    2114  * Process RSS feed widget data and optionally retrieve feed items.
    2115  *
    2116  * The feed widget can not have more than 20 items or it will reset back to the
    2117  * default, which is 10.
    2118  *
    2119  * The resulting array has the feed title, feed url, feed link (from channel),
    2120  * feed items, error (if any), and whether to show summary, author, and date.
    2121  * All respectively in the order of the array elements.
    2122  *
    2123  * @since 2.5.0
    2124  *
    2125  * @param array $widget_rss RSS widget feed data. Expects unescaped data.
    2126  * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
    2127  * @return array
    2128  */
    2129 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
    2130     $items = (int) $widget_rss['items'];
    2131     if ( $items < 1 || 20 < $items )
    2132         $items = 10;
    2133     $url           = sanitize_url(strip_tags( $widget_rss['url'] ));
    2134     $title         = trim(strip_tags( $widget_rss['title'] ));
    2135     $show_summary  = (int) $widget_rss['show_summary'];
    2136     $show_author   = (int) $widget_rss['show_author'];
    2137     $show_date     = (int) $widget_rss['show_date'];
    2138 
    2139     if ( $check_feed ) {
    2140         $rss = fetch_feed($url);
    2141         $error = false;
    2142         $link = '';
    2143         if ( is_wp_error($rss) ) {
    2144             $error = $rss->get_error_message();
    2145         } else {
    2146             $link = clean_url(strip_tags($rss->get_permalink()));
    2147             while ( stristr($link, 'http') != $link )
    2148                 $link = substr($link, 1);
    2149         }
    2150     }
    2151 
    2152     return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
    2153 }
    2154 
    2155 /**
    2156  * Register RSS widget to allow multiple RSS widgets on startup.
    2157  *
    2158  * @since 2.2.0
    2159  */
    2160 function wp_widget_rss_register() {
    2161     $options = get_option('widget_rss');
    2162     if ( !is_array($options) )
    2163         $options = array();
    2164 
    2165     $widget_ops = array('classname' => 'widget_rss', 'description' => __( 'Entries from any RSS or Atom feed' ));
    2166     $control_ops = array('width' => 400, 'height' => 200, 'id_base' => 'rss');
    2167     $name = __('RSS');
    2168 
    2169     $id = false;
    2170     foreach ( (array) array_keys($options) as $o ) {
    2171         // Old widgets can have null values for some reason
    2172         if ( !isset($options[$o]['url']) || !isset($options[$o]['title']) || !isset($options[$o]['items']) )
    2173             continue;
    2174         $id = "rss-$o"; // Never never never translate an id
    2175         wp_register_sidebar_widget($id, $name, 'wp_widget_rss', $widget_ops, array( 'number' => $o ));
    2176         wp_register_widget_control($id, $name, 'wp_widget_rss_control', $control_ops, array( 'number' => $o ));
    2177     }
    2178 
    2179     // If there are none, we register the widget's existance with a generic template
    2180     if ( !$id ) {
    2181         wp_register_sidebar_widget( 'rss-1', $name, 'wp_widget_rss', $widget_ops, array( 'number' => -1 ) );
    2182         wp_register_widget_control( 'rss-1', $name, 'wp_widget_rss_control', $control_ops, array( 'number' => -1 ) );
    2183     }
    2184 }
    2185 
    2186 /**
    2187  * Display tag cloud widget.
    2188  *
    2189  * @since 2.3.0
    2190  *
    2191  * @param array $args Widget arguments.
    2192  */
    2193 function wp_widget_tag_cloud($args) {
    2194     extract($args);
    2195     $options = get_option('widget_tag_cloud');
    2196     $title = empty($options['title']) ? __('Tags') : apply_filters('widget_title', $options['title']);
    2197 
    2198     echo $before_widget;
    2199     echo $before_title . $title . $after_title;
    2200     wp_tag_cloud();
    2201     echo $after_widget;
    2202 }
    2203 
    2204 /**
    2205  * Manage WordPress Tag Cloud widget options.
    2206  *
    2207  * Displays management form for changing the tag cloud widget title.
    2208  *
    2209  * @since 2.3.0
    2210  */
    2211 function wp_widget_tag_cloud_control() {
    2212     $options = $newoptions = get_option('widget_tag_cloud');
    2213 
    2214     if ( isset($_POST['tag-cloud-submit']) ) {
    2215         $newoptions['title'] = strip_tags(stripslashes($_POST['tag-cloud-title']));
    2216     }
    2217 
    2218     if ( $options != $newoptions ) {
    2219         $options = $newoptions;
    2220         update_option('widget_tag_cloud', $options);
    2221     }
    2222 
    2223     $title = attribute_escape( $options['title'] );
    2224 ?>
    2225     <p><label for="tag-cloud-title">
    2226     <?php _e('Title:') ?> <input type="text" class="widefat" id="tag-cloud-title" name="tag-cloud-title" value="<?php echo $title ?>" /></label>
    2227     </p>
    2228     <input type="hidden" name="tag-cloud-submit" id="tag-cloud-submit" value="1" />
    2229 <?php
    2230 }
    2231 
    2232 /**
    2233  * Register all of the default WordPress widgets on startup.
    2234  *
    2235  * Calls 'widgets_init' action after all of the WordPress widgets have been
    2236  * registered.
    2237  *
    2238  * @since 2.2.0
    2239  */
    2240 function wp_widgets_init() {
    2241     if ( !is_blog_installed() )
    2242         return;
    2243 
    2244     new WP_Widget_Pages();
    2245 
    2246     $widget_ops = array('classname' => 'widget_calendar', 'description' => __( "A calendar of your blog's posts") );
    2247     wp_register_sidebar_widget('calendar', __('Calendar'), 'wp_widget_calendar', $widget_ops);
    2248     wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control' );
    2249 
    2250     new WP_Widget_Archives();
    2251 
    2252     new WP_Widget_Links();
    2253 
    2254     $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
    2255     wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $widget_ops);
    2256     wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control' );
    2257 
    2258     new WP_Widget_Search();
    2259 
    2260     $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your blog") );
    2261     wp_register_sidebar_widget('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries', $widget_ops);
    2262     wp_register_widget_control('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries_control' );
    2263 
    2264     $widget_ops = array('classname' => 'widget_tag_cloud', 'description' => __( "Your most used tags in cloud format") );
    2265     wp_register_sidebar_widget('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud', $widget_ops);
    2266     wp_register_widget_control('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud_control' );
    2267 
    2268     wp_widget_categories_register();
    2269     wp_widget_text_register();
    2270     wp_widget_rss_register();
    2271     wp_widget_recent_comments_register();
    2272 
    2273     do_action('widgets_init');
    2274 }
    2275 
    2276 add_action('init', 'wp_widgets_init', 1);
    2277 
    2278 /*
    2279  * Pattern for multi-widget (allows multiple instances such as the text widget).
    2280  *
    2281  * Make sure to close the comments after copying.
    2282 
    2283 /**
    2284  * Displays widget.
    2285  *
    2286  * Supports multiple widgets.
    2287  *
    2288  * @param array $args Widget arguments.
    2289  * @param array|int $widget_args Widget number. Which of the several widgets of this type do we mean.
    2290  * /
    2291 function widget_many( $args, $widget_args = 1 ) {
    2292     extract( $args, EXTR_SKIP );
    2293     if ( is_numeric($widget_args) )
    2294         $widget_args = array( 'number' => $widget_args );
    2295     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    2296     extract( $widget_args, EXTR_SKIP );
    2297 
    2298     // Data should be stored as array:  array( number => data for that instance of the widget, ... )
    2299     $options = get_option('widget_many');
    2300     if ( !isset($options[$number]) )
    2301         return;
    2302 
    2303     echo $before_widget;
    2304 
    2305     // Do stuff for this widget, drawing data from $options[$number]
    2306 
    2307     echo $after_widget;
    2308 }
    2309 
    2310 /**
    2311  * Displays form for a particular instance of the widget.
    2312  *
    2313  * Also updates the data after a POST submit.
    2314  *
    2315  * @param array|int $widget_args Widget number. Which of the several widgets of this type do we mean.
    2316  * /
    2317 function widget_many_control( $widget_args = 1 ) {
    2318     global $wp_registered_widgets;
    2319     static $updated = false; // Whether or not we have already updated the data after a POST submit
    2320 
    2321     if ( is_numeric($widget_args) )
    2322         $widget_args = array( 'number' => $widget_args );
    2323     $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    2324     extract( $widget_args, EXTR_SKIP );
    2325 
    2326     // Data should be stored as array:  array( number => data for that instance of the widget, ... )
    2327     $options = get_option('widget_many');
    2328     if ( !is_array($options) )
    2329         $options = array();
    2330 
    2331     // We need to update the data
    2332     if ( !$updated && !empty($_POST['sidebar']) ) {
    2333         // Tells us what sidebar to put the data in
    2334         $sidebar = (string) $_POST['sidebar'];
    2335 
    2336         $sidebars_widgets = wp_get_sidebars_widgets();
    2337         if ( isset($sidebars_widgets[$sidebar]) )
    2338             $this_sidebar =& $sidebars_widgets[$sidebar];
    2339         else
    2340             $this_sidebar = array();
    2341 
    2342         foreach ( $this_sidebar as $_widget_id ) {
    2343             // Remove all widgets of this type from the sidebar.  We'll add the new data in a second.  This makes sure we don't get any duplicate data
    2344             // since widget ids aren't necessarily persistent across multiple updates
    2345             if ( 'widget_many' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    2346                 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
    2347                 if ( !in_array( "many-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed. "many-$widget_number" is "{id_base}-{widget_number}
    2348                     unset($options[$widget_number]);
    2349             }
    2350         }
    2351 
    2352         foreach ( (array) $_POST['widget-many'] as $widget_number => $widget_many_instance ) {
    2353             // compile data from $widget_many_instance
    2354             if ( !isset($widget_many_instance['something']) && isset($options[$widget_number]) ) // user clicked cancel
    2355                 continue;
    2356             $something = wp_specialchars( $widget_many_instance['something'] );
    2357             $options[$widget_number] = array( 'something' => $something );  // Even simple widgets should store stuff in array, rather than in scalar
    2358         }
    2359 
    2360         update_option('widget_many', $options);
    2361 
    2362         $updated = true; // So that we don't go through this more than once
    2363     }
    2364 
    2365 
    2366     // Here we echo out the form
    2367     if ( -1 == $number ) { // We echo out a template for a form which can be converted to a specific form later via JS
    2368         $something = '';
    2369         $number = '%i%';
    2370     } else {
    2371         $something = attribute_escape($options[$number]['something']);
    2372     }
    2373 
    2374     // The form has inputs with names like widget-many[$number][something] so that all data for that instance of
    2375     // the widget are stored in one $_POST variable: $_POST['widget-many'][$number]
    2376 ?>
    2377         <p>
    2378             <input class="widefat" id="widget-many-something-<?php echo $number; ?>" name="widget-many[<?php echo $number; ?>][something]" type="text" value="<?php echo $data; ?>" />
    2379             <input type="hidden" id="widget-many-submit-<?php echo $number; ?>" name="widget-many[<?php echo $number; ?>][submit]" value="1" />
    2380         </p>
    2381 <?php
    2382 }
    2383 
    2384 /**
    2385  * Registers each instance of our widget on startup.
    2386  * /
    2387 function widget_many_register() {
    2388     if ( !$options = get_option('widget_many') )
    2389         $options = array();
    2390 
    2391     $widget_ops = array('classname' => 'widget_many', 'description' => __('Widget which allows multiple instances'));
    2392     $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'many');
    2393     $name = __('Many');
    2394 
    2395     $registered = false;
    2396     foreach ( array_keys($options) as $o ) {
    2397         // Old widgets can have null values for some reason
    2398         if ( !isset($options[$o]['something']) ) // we used 'something' above in our exampple.  Replace with with whatever your real data are.
    2399             continue;
    2400 
    2401         // $id should look like {$id_base}-{$o}
    2402         $id = "many-$o"; // Never never never translate an id
    2403         $registered = true;
    2404         wp_register_sidebar_widget( $id, $name, 'widget_many', $widget_ops, array( 'number' => $o ) );
    2405         wp_register_widget_control( $id, $name, 'widget_many_control', $control_ops, array( 'number' => $o ) );
    2406     }
    2407 
    2408     // If there are none, we register the widget's existance with a generic template
    2409     if ( !$registered ) {
    2410         wp_register_sidebar_widget( 'many-1', $name, 'widget_many', $widget_ops, array( 'number' => -1 ) );
    2411         wp_register_widget_control( 'many-1', $name, 'widget_many_control', $control_ops, array( 'number' => -1 ) );
    2412     }
    2413 }
    2414 
    2415 // This is important
    2416 add_action( 'widgets_init', 'widget_many_register' );
    2417 
    2418 */
    2419 
    2420 ?>
     902            $name = $name[0];
     903    }
     904
     905    $id = sanitize_title($name);
     906    $options = array();
     907    if ( !empty($width) )
     908        $options['width'] = $width;
     909    if ( !empty($height) )
     910        $options['height'] = $height;
     911    $params = array_slice(func_get_args(), 4);
     912    $args = array($id, $name, $control_callback, $options);
     913    if ( !empty($params) )
     914        $args = array_merge($args, $params);
     915
     916    call_user_func_array('wp_register_widget_control', $args);
     917}
     918
     919/**
     920 * Alias of {@link wp_unregister_widget_control()}.
     921 *
     922 * @since 2.2.0
     923 * @see wp_unregister_widget_control()
     924 *
     925 * @param int|string $id Widget ID.
     926 */
     927function unregister_widget_control($id) {
     928    return wp_unregister_widget_control($id);
     929}
  • trunk/wp-settings.php

    r10737 r10795  
    328328require (ABSPATH . WPINC . '/media.php');
    329329require (ABSPATH . WPINC . '/http.php');
     330require (ABSPATH . WPINC . '/widgets.php');
    330331
    331332if ( !defined('WP_CONTENT_URL') )
Note: See TracChangeset for help on using the changeset viewer.