Make WordPress Core

Ticket #28216: 28216.exit-early-implementation.patch

File 28216.exit-early-implementation.patch, 2.2 KB (added by mdwheele, 9 years ago)

Implementation that exits early.

  • tests/phpunit/tests/widgets.php

     
    4141        }
    4242
    4343        /**
     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        /**
    4462         * @see register_sidebars()
    4563         */
    4664        function test_register_sidebars_single() {
  • src/wp-includes/widgets.php

     
    573573         * @since 2.8.0
    574574         * @access public
    575575         *
    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.
    577577         */
    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();
    580585        }
    581586
    582587        /**
     
    585590         * @since 2.8.0
    586591         * @access public
    587592         *
    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.
    589594         */
    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 ] );
    592602        }
    593603
    594604        /**