Ticket #28216: 28216.exit-early-implementation.patch
File 28216.exit-early-implementation.patch, 2.2 KB (added by , 10 years ago) |
---|
-
tests/phpunit/tests/widgets.php
41 41 } 42 42 43 43 /** 44 * @see register_widget() 45 * @see unregister_widget() 46 * @group 28216 47 */ 48 function test_register_and_unregister_widget_instance() { 49 global $wp_widget_factory; 50 51 $widget = new WP_Widget_Search(); 52 $widget_class = get_class( $widget ); 53 54 register_widget( $widget ); 55 $this->assertArrayHasKey( $widget_class, $wp_widget_factory->widgets ); 56 57 unregister_widget( $widget ); 58 $this->assertArrayNotHasKey( $widget_class, $wp_widget_factory->widgets ); 59 } 60 61 /** 44 62 * @see register_sidebars() 45 63 */ 46 64 function test_register_sidebars_single() { -
src/wp-includes/widgets.php
573 573 * @since 2.8.0 574 574 * @access public 575 575 * 576 * @param string $widget_class The name of a {@see WP_Widget} subclass.576 * @param string | WP_Widget $widgetish Either the name of a {@see WP_Widget} subclass or an instance of a {@see WP_Widget} subclass. 577 577 */ 578 public function register( $widget_class ) { 579 $this->widgets[$widget_class] = new $widget_class(); 578 public function register( $widgetish ) { 579 if ( $widgetish instanceof WP_Widget ) { 580 $this->widgets[ get_class( $widgetish ) ] = $widgetish; 581 return; 582 } 583 584 $this->widgets[ $widgetish ] = new $widgetish(); 580 585 } 581 586 582 587 /** … … 585 590 * @since 2.8.0 586 591 * @access public 587 592 * 588 * @param string $widget_class The name of a {@see WP_Widget} subclass.593 * @param string | WP_Widget $widgetish Either the name of a {@see WP_Widget} subclass or an instance of a {@see WP_Widget} subclass. 589 594 */ 590 public function unregister( $widget_class ) { 591 unset( $this->widgets[ $widget_class ] ); 595 public function unregister( $widgetish ) { 596 if ( $widgetish instanceof WP_Widget ) { 597 unset( $this->widgets[ get_class( $widgetish ) ] ); 598 return; 599 } 600 601 unset( $this->widgets[ $widgetish ] ); 592 602 } 593 603 594 604 /**