Changeset 51070
- Timestamp:
- 06/04/2021 10:46:22 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-widget.php
r50961 r51070 153 153 * 154 154 * @param string $id_base Optional. Base ID for the widget, lowercase and unique. If left empty, 155 * a portion of the widget's class name will be used. Has to be unique.155 * a portion of the widget's PHP class name will be used. Has to be unique. 156 156 * @param string $name Name for the widget displayed on the configuration page. 157 157 * @param array $widget_options Optional. Widget options. See wp_register_sidebar_widget() for … … 189 189 * 190 190 * @param string $id_base Optional. Base ID for the widget, lowercase and unique. If left empty, 191 * a portion of the widget's class name will be used. Has to be unique.191 * a portion of the widget's PHP class name will be used. Has to be unique. 192 192 * @param string $name Name for the widget displayed on the configuration page. 193 193 * @param array $widget_options Optional. Widget options. See wp_register_sidebar_widget() for … … 210 210 * @since 4.4.0 Array format field names are now accepted. 211 211 * 212 * @param string $field_name Field name 213 * @return string Name attribute for $field_name212 * @param string $field_name Field name. 213 * @return string Name attribute for `$field_name`. 214 214 */ 215 215 public function get_field_name( $field_name ) { 216 216 $pos = strpos( $field_name, '[' ); 217 if ( false === $pos ) { 218 return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']'; 217 218 if ( false !== $pos ) { 219 // Replace the first occurrence of '[' with ']['. 220 $field_name = '[' . substr_replace( $field_name, '][', $pos, strlen( '[' ) ); 219 221 } else { 220 return 'widget-' . $this->id_base . '[' . $this->number . '][' . substr_replace( $field_name, '][', $pos, strlen( '[' ) ); 221 } 222 $field_name = '[' . $field_name . ']'; 223 } 224 225 return 'widget-' . $this->id_base . '[' . $this->number . ']' . $field_name; 222 226 } 223 227 … … 235 239 */ 236 240 public function get_field_id( $field_name ) { 237 return 'widget-' . $this->id_base . '-' . $this->number . '-' . trim( str_replace( array( '[]', '[', ']' ), array( '', '-', '' ), $field_name ), '-' ); 241 $field_name = str_replace( array( '[]', '[', ']' ), array( '', '-', '' ), $field_name ); 242 $field_name = trim( $field_name, '-' ); 243 244 return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name; 238 245 } 239 246 … … 467 474 */ 468 475 $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this ); 476 469 477 if ( false !== $instance ) { 470 478 $all_instances[ $number ] = $instance; … … 522 530 523 531 $return = null; 532 524 533 if ( false !== $instance ) { 525 534 $return = $this->form( $instance ); … … 543 552 do_action_ref_array( 'in_widget_form', array( &$this, &$return, $instance ) ); 544 553 } 554 545 555 return $return; 546 556 } … … 555 565 */ 556 566 public function _register_one( $number = -1 ) { 557 wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); 558 _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); 559 _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); 567 wp_register_sidebar_widget( 568 $this->id, 569 $this->name, 570 $this->_get_display_callback(), 571 $this->widget_options, 572 array( 'number' => $number ) 573 ); 574 575 _register_widget_update_callback( 576 $this->id_base, 577 $this->_get_update_callback(), 578 $this->control_options, 579 array( 'number' => -1 ) 580 ); 581 582 _register_widget_form_callback( 583 $this->id, 584 $this->name, 585 $this->_get_form_callback(), 586 $this->control_options, 587 array( 'number' => $number ) 588 ); 560 589 } 561 590 … … 602 631 603 632 unset( $settings['_multiwidget'], $settings['__i__'] ); 633 604 634 return $settings; 605 635 }
Note: See TracChangeset
for help on using the changeset viewer.