Ticket #30315: 30315.1.diff
File 30315.1.diff, 6.3 KB (added by , 11 years ago) |
---|
-
wp-includes/widgets.php
25 25 26 26 public $id_base; // Root id for all widgets of this type. 27 27 public $name; // Name for this widget type. 28 public $widget_options; // Option array passed to wp_register_sidebar_widget()28 public $widget_options; // Option array passed to wp_register_sidebar_widget() 29 29 public $control_options; // Option array passed to wp_register_widget_control() 30 30 31 public $number = false; // Unique ID number of the current instance.32 public $id = false; // Unique ID string of the current instance (id_base-number)31 public $number = false; // Unique ID number of the current instance. 32 public $id = false; // Unique ID string of the current instance (id_base-number) 33 33 public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. 34 34 35 35 // Member functions that you must over-ride. 36 36 37 /** Echo the widget content. 37 /** 38 * Echo the widget content. 38 39 * 39 40 * Subclasses should over-ride this function to generate their widget code. 40 41 * 42 * @since 2.8.0 43 * 41 44 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. 42 45 * @param array $instance The settings for the particular instance of the widget 43 46 */ … … 45 48 die('function WP_Widget::widget() must be over-ridden in a sub-class.'); 46 49 } 47 50 48 /** Update a particular instance. 51 /** 52 * Update a particular instance. 49 53 * 50 54 * This function should check that $new_instance is set correctly. 51 55 * The newly calculated value of $instance should be returned. 52 56 * If "false" is returned, the instance won't be saved/updated. 53 57 * 58 * @since 2.8.0 59 * 54 60 * @param array $new_instance New settings for this instance as input by the user via form() 55 61 * @param array $old_instance Old settings for this instance 56 62 * @return array Settings to save or bool false to cancel saving … … 59 65 return $new_instance; 60 66 } 61 67 62 /** Echo the settings update form 68 /** 69 * Echo the settings update form 63 70 * 71 * @since 2.8.0 72 * 64 73 * @param array $instance Current settings 65 74 */ 66 75 public function form($instance) { … … 122 131 return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name; 123 132 } 124 133 125 // Private Functions. Don't worry about these. 126 134 /** 135 * Register all widget instances of this widget class. 136 * 137 * @since 2.8.0 138 * 139 * @access private 140 */ 127 141 public function _register() { 128 142 $settings = $this->get_settings(); 129 143 $empty = true; … … 146 160 } 147 161 } 148 162 163 /** 164 * Set the internal order number for the widget instance. 165 * 166 * @since 2.8.0 167 * 168 * @access private 169 * 170 * @param int $number The unique order number of this widget instance 171 * compared to other instances of the same class. 172 */ 149 173 public function _set($number) { 150 174 $this->number = $number; 151 175 $this->id = $this->id_base . '-' . $number; … … 362 386 return $return; 363 387 } 364 388 365 /** Helper function: Registers a single instance. */ 389 /** 390 * Register an instance of the widget class. 391 * 392 * @since 2.8.0 393 * 394 * @access private 395 * 396 * @param integer $number The unique order number of this widget instance 397 * compared to other instances of the same class. 398 */ 366 399 public function _register_one($number = -1) { 367 400 wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); 368 401 _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); 369 402 _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); 370 403 } 371 404 405 /** 406 * Save the settings for all instances of the widget class. 407 * 408 * @since 2.8.0 409 * 410 * @param array $settings Multi-dimensional array of widget instance settings. 411 */ 372 412 public function save_settings($settings) { 373 413 $settings['_multiwidget'] = 1; 374 414 update_option( $this->option_name, $settings ); 375 415 } 376 416 417 /** 418 * Get the settings for all instances of the widget class. 419 * 420 * @since 2.8.0 421 * 422 * @return array Multi-dimensional array of widget instance settings. 423 */ 377 424 public function get_settings() { 425 378 426 $settings = get_option($this->option_name); 379 427 380 428 if ( false === $settings && isset($this->alt_option_name) ) … … 407 455 add_action( 'widgets_init', array( $this, '_register_widgets' ), 100 ); 408 456 } 409 457 458 /** 459 * Register a widget class. 460 * 461 * @since 2.8.0 462 * 463 * @param mixed $widget_class A subclass of WP_Widget. 464 */ 410 465 public function register($widget_class) { 411 466 $this->widgets[$widget_class] = new $widget_class(); 412 467 } 413 468 469 /** 470 * Unregister a widget class. 471 * 472 * @since 2.8.0 473 * 474 * @param mixed $widget_class A subclass of WP_Widget. 475 */ 414 476 public function unregister($widget_class) { 415 477 if ( isset($this->widgets[$widget_class]) ) 416 478 unset($this->widgets[$widget_class]); … … 448 510 $wp_registered_sidebars = array(); 449 511 450 512 /** 451 * Stores the registeredwidgets.513 * Stores instances of widgets. 452 514 * 453 515 * @global array $wp_registered_widgets 454 516 * @since 2.2.0 … … 683 745 } 684 746 685 747 /** 686 * Register widget for use in sidebars.748 * Register an instance of a widget. 687 749 * 688 750 * The default widget option is 'classname' that can be overridden. 689 751 * … … 698 760 * @param int|string $id Widget ID. 699 761 * @param string $name Widget display title. 700 762 * @param callback $output_callback Run when widget is called. 701 * @param array|string $options Optional. Widget Options. 763 * @param array $options { 764 * An array of supplementary widget options for the instance. Optional. 765 * 766 * @type string $classname Classname for the widget's HTML container. 767 * Optional. Defaults to the output callback. 768 * } 702 769 * @param mixed $params,... Widget parameters to add to widget. 703 770 * @return null Will return if $output_callback is empty after removing widget. 704 771 */ … … 1202 1269 /* Internal Functions */ 1203 1270 1204 1271 /** 1205 * Retrieve full list of sidebars and their widget s.1272 * Retrieve full list of sidebars and their widget instance IDs. 1206 1273 * 1207 1274 * Will upgrade sidebar widget list, if needed. Will also save updated list, if 1208 1275 * needed.