Ticket #28216: 28216.spl_object_hash-approach.patch
File 28216.spl_object_hash-approach.patch, 2.2 KB (added by , 8 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 $widspl_object_hash = spl_object_hash( $widget ); 53 54 register_widget( $widget ); 55 $this->assertArrayHasKey( $widspl_object_hash, $wp_widget_factory->widgets ); 56 57 unregister_widget( $widget ); 58 $this->assertArrayNotHasKey( $widspl_object_hash, $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 $widspl_object_hash 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( $widspl_object_hash ) { 579 $this->widgets[$widspl_object_hash] = new $widspl_object_hash(); 578 public function register( $widgetish ) { 579 if ( $widgetish instanceof WP_Widget ) { 580 $this->widgets[ spl_object_hash( $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 $widspl_object_hash 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( $widspl_object_hash ) { 591 unset( $this->widgets[ $widspl_object_hash ] ); 594 public function unregister( $widgetish ) { 595 if ( $widgetish instanceof WP_Widget ) { 596 unset( $this->widgets[ spl_object_hash( $widgetish ) ] ); 597 } else { 598 unset( $this->widgets[ $widgetish ] ); 599 } 592 600 } 593 601 594 602 /**