Changeset 28527 for trunk/src/wp-includes/widgets.php
- Timestamp:
- 05/19/2014 03:42:00 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/widgets.php
r28338 r28527 24 24 class WP_Widget { 25 25 26 var$id_base; // Root id for all widgets of this type.27 var$name; // Name for this widget type.28 var$widget_options; // Option array passed to wp_register_sidebar_widget()29 var$control_options; // Option array passed to wp_register_widget_control()30 31 var$number = false; // Unique ID number of the current instance.32 var$id = false; // Unique ID string of the current instance (id_base-number)33 var$updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.26 public $id_base; // Root id for all widgets of this type. 27 public $name; // Name for this widget type. 28 public $widget_options; // Option array passed to wp_register_sidebar_widget() 29 public $control_options; // Option array passed to wp_register_widget_control() 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) 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. … … 42 42 * @param array $instance The settings for the particular instance of the widget 43 43 */ 44 function widget($args, $instance) {44 public function widget($args, $instance) { 45 45 die('function WP_Widget::widget() must be over-ridden in a sub-class.'); 46 46 } … … 56 56 * @return array Settings to save or bool false to cancel saving 57 57 */ 58 function update($new_instance, $old_instance) {58 public function update($new_instance, $old_instance) { 59 59 return $new_instance; 60 60 } … … 64 64 * @param array $instance Current settings 65 65 */ 66 function form($instance) {66 public function form($instance) { 67 67 echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>'; 68 68 return 'noform'; … … 84 84 * - height: currently not used but may be needed in the future 85 85 */ 86 function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {86 public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) { 87 87 $this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base); 88 88 $this->name = $name; … … 95 95 * PHP4 constructor 96 96 */ 97 function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) {97 public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) { 98 98 WP_Widget::__construct( $id_base, $name, $widget_options, $control_options ); 99 99 } … … 107 107 * @return string Name attribute for $field_name 108 108 */ 109 function get_field_name($field_name) {109 public function get_field_name($field_name) { 110 110 return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']'; 111 111 } … … 119 119 * @return string ID attribute for $field_name 120 120 */ 121 function get_field_id($field_name) {121 public function get_field_id($field_name) { 122 122 return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name; 123 123 } … … 125 125 // Private Functions. Don't worry about these. 126 126 127 function _register() {127 public function _register() { 128 128 $settings = $this->get_settings(); 129 129 $empty = true; … … 147 147 } 148 148 149 function _set($number) {149 public function _set($number) { 150 150 $this->number = $number; 151 151 $this->id = $this->id_base . '-' . $number; 152 152 } 153 153 154 function _get_display_callback() {154 public function _get_display_callback() { 155 155 return array($this, 'display_callback'); 156 156 } 157 157 158 function _get_update_callback() {158 public function _get_update_callback() { 159 159 return array($this, 'update_callback'); 160 160 } 161 161 162 function _get_form_callback() {162 public function _get_form_callback() { 163 163 return array($this, 'form_callback'); 164 164 } … … 174 174 * @return bool True if Customizer is on, false if not. 175 175 */ 176 function is_preview() {176 public function is_preview() { 177 177 global $wp_customize; 178 178 return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ; … … 182 182 * Just finds the instance and calls widget(). 183 183 * Do NOT over-ride this function. */ 184 function display_callback( $args, $widget_args = 1 ) {184 public function display_callback( $args, $widget_args = 1 ) { 185 185 if ( is_numeric($widget_args) ) 186 186 $widget_args = array( 'number' => $widget_args ); … … 230 230 * @param mixed $deprecated Not used. 231 231 */ 232 function update_callback( $deprecated = 1 ) {232 public function update_callback( $deprecated = 1 ) { 233 233 global $wp_registered_widgets; 234 234 … … 310 310 * Do NOT over-ride this function. 311 311 */ 312 function form_callback( $widget_args = 1 ) {312 public function form_callback( $widget_args = 1 ) { 313 313 if ( is_numeric($widget_args) ) 314 314 $widget_args = array( 'number' => $widget_args ); … … 364 364 365 365 /** Helper function: Registers a single instance. */ 366 function _register_one($number = -1) {366 public function _register_one($number = -1) { 367 367 wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); 368 368 _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); … … 370 370 } 371 371 372 function save_settings($settings) {372 public function save_settings($settings) { 373 373 $settings['_multiwidget'] = 1; 374 374 update_option( $this->option_name, $settings ); 375 375 } 376 376 377 function get_settings() {377 public function get_settings() { 378 378 $settings = get_option($this->option_name); 379 379 … … 402 402 */ 403 403 class WP_Widget_Factory { 404 var$widgets = array();405 406 function WP_Widget_Factory() {404 public $widgets = array(); 405 406 public function WP_Widget_Factory() { 407 407 add_action( 'widgets_init', array( $this, '_register_widgets' ), 100 ); 408 408 } 409 409 410 function register($widget_class) {410 public function register($widget_class) { 411 411 $this->widgets[$widget_class] = new $widget_class(); 412 412 } 413 413 414 function unregister($widget_class) {414 public function unregister($widget_class) { 415 415 if ( isset($this->widgets[$widget_class]) ) 416 416 unset($this->widgets[$widget_class]); 417 417 } 418 418 419 function _register_widgets() {419 public function _register_widgets() { 420 420 global $wp_registered_widgets; 421 421 $keys = array_keys($this->widgets);
Note: See TracChangeset
for help on using the changeset viewer.