Ticket #44098: 44098.diff
File 44098.diff, 3.0 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/widgets.php
162 162 $number = 1; 163 163 164 164 foreach ( $wp_registered_widgets as $widget_id => $widget ) { 165 if ( preg_match( '/' . $id_base. '-([0-9]+)$/', $widget_id, $matches ) ) {165 if ( preg_match( '/' . preg_quote( $id_base, '/' ) . '-([0-9]+)$/', $widget_id, $matches ) ) { 166 166 $number = max( $number, $matches[1] ); 167 167 } 168 168 } -
src/wp-includes/class-wp-widget.php
164 164 $id_base = strtolower( $id_base ); 165 165 } else { 166 166 $id_base = preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ); 167 $id_base = str_replace( '\\', '-', $id_base );168 167 } 169 168 170 169 $this->id_base = $id_base; … … 173 172 $this->widget_options = wp_parse_args( 174 173 $widget_options, 175 174 array( 176 'classname' => $this->option_name,175 'classname' => str_replace( '\\', '_', $this->option_name ), 177 176 'customize_selective_refresh' => false, 178 177 ) 179 178 ); -
tests/phpunit/tests/widgets.php
428 428 /** 429 429 * @ticket 44098 430 430 * @see WP_Widget::__construct() 431 * @dataProvider data_wp_widget_ id_base431 * @dataProvider data_wp_widget_classname 432 432 */ 433 function test_wp_widget_ id_base( $expected, $widget_class ) {433 function test_wp_widget_classname( $expected, $widget_class ) { 434 434 require_once DIR_TESTDATA . '/widgets/custom-widget-classes.php'; 435 435 436 436 $widget = new $widget_class( '', 'Foo' ); 437 437 438 $this->assertSame( $expected, $widget-> id_base);438 $this->assertSame( $expected, $widget->widget_options['classname'] ); 439 439 } 440 440 441 441 /** 442 442 * Data provider. 443 443 * 444 * Passes the expected ` id_base` value and the class name.444 * Passes the expected `classname` value and the class name. 445 445 * 446 446 * @since 5.8.0 447 447 * 448 448 * @return array { 449 449 * @type array { 450 * @type string $expected The expected ` id_base` value to be returned.450 * @type string $expected The expected `classname` value to be returned. 451 451 * @type string $widget_class The widget class name for creating an instance. 452 452 * } 453 453 * } 454 454 */ 455 function data_wp_widget_ id_base() {455 function data_wp_widget_classname() { 456 456 return array( 457 457 array( 458 ' search',458 'widget_search', 459 459 'WP_Widget_Search', 460 460 ), 461 461 array( 462 ' test-sub-sub-namespaced_widget',462 'widget_test_sub_sub_namespaced_widget', 463 463 'Test\Sub\Sub\Namespaced_Widget', 464 464 ), 465 465 array( 466 ' non_namespaced_widget',466 'widget_non_namespaced_widget', 467 467 'Non_Namespaced_Widget', 468 468 ), 469 469 );