Ticket #28216: 28216.branching-implementation.patch
File 28216.branching-implementation.patch, 2.2 KB (added by , 9 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 } else { 582 $this->widgets[ $widgetish ] = new $widgetish(); 583 } 580 584 } 581 585 582 586 /** … … 585 589 * @since 2.8.0 586 590 * @access public 587 591 * 588 * @param string $widget_class The name of a {@see WP_Widget} subclass.592 * @param string | WP_Widget $widgetish Either the name of a {@see WP_Widget} subclass or an instance of a {@see WP_Widget} subclass. 589 593 */ 590 public function unregister( $widget_class ) { 591 unset( $this->widgets[ $widget_class ] ); 594 public function unregister( $widgetish ) { 595 if ( $widgetish instanceof WP_Widget ) { 596 unset( $this->widgets[ get_class( $widgetish ) ] ); 597 } else { 598 unset( $this->widgets[ $widgetish ] ); 599 } 592 600 } 593 601 594 602 /**