@@ -152,7 +152,7 @@ public function form( $instance ) {
152
152
* @since 2.8.0
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
158
158
* information on accepted arguments. Default empty array.
@@ -188,7 +188,7 @@ public function __construct( $id_base, $name, $widget_options = array(), $contro
188
188
* @see WP_Widget::__construct()
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
194
194
* information on accepted arguments. Default empty array.
@@ -209,16 +209,20 @@ public function WP_Widget( $id_base, $name, $widget_options = array(), $control_
209
209
* @since 2.8.0
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_name
212
+ * @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 ( ' [ ' ) ) ;
222
+ $ field_name = '[ ' . $ field_name . '] ' ;
221
223
}
224
+
225
+ return 'widget- ' . $ this ->id_base . '[ ' . $ this ->number . '] ' . $ field_name ;
222
226
}
223
227
224
228
/**
@@ -234,7 +238,10 @@ public function get_field_name( $field_name ) {
234
238
* @return string ID attribute for `$field_name`.
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
240
247
/**
@@ -466,6 +473,7 @@ public function update_callback( $deprecated = 1 ) {
466
473
* @param WP_Widget $widget The current widget instance.
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 ;
471
479
}
@@ -521,6 +529,7 @@ public function form_callback( $widget_args = 1 ) {
521
529
$ instance = apply_filters ( 'widget_form_callback ' , $ instance , $ this );
522
530
523
531
$ return = null ;
532
+
524
533
if ( false !== $ instance ) {
525
534
$ return = $ this ->form ( $ instance );
526
535
@@ -542,6 +551,7 @@ public function form_callback( $widget_args = 1 ) {
542
551
*/
543
552
do_action_ref_array ( 'in_widget_form ' , array ( &$ this , &$ return , $ instance ) );
544
553
}
554
+
545
555
return $ return ;
546
556
}
547
557
@@ -554,9 +564,28 @@ public function form_callback( $widget_args = 1 ) {
554
564
* compared to other instances of the same class. Default -1.
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
562
591
/**
@@ -601,6 +630,7 @@ public function get_settings() {
601
630
}
602
631
603
632
unset( $ settings ['_multiwidget ' ], $ settings ['__i__ ' ] );
633
+
604
634
return $ settings ;
605
635
}
606
636
}
0 commit comments