Make WordPress Core


Ignore:
Timestamp:
10/13/2015 01:12:12 AM (9 years ago)
Author:
wonderboymusic
Message:

Widgets: when getting settings, and none exist, set them to empty to avoid extraneous database queries on subsequent requests.

Adds unit tests.

Props kovshenin, MikeHansenMe, dlh.
Fixes #26876.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets.php

    r34817 r35100  
    466466        unset( $option_value['_multiwidget'] );
    467467
     468        // Pretend this widget is new.
     469        delete_option( 'widget_nav_menu' );
     470        $never_used = get_option( 'widget_nav_menu' );
     471        $this->assertFalse( $never_used );
     472
    468473        wp_widgets_init();
    469474        $wp_widget_search = $wp_registered_widgets['search-2']['callback'][0];
     
    476481            $this->assertEquals( $settings[ $widget_number ], $option_value[ $widget_number ] );
    477482        }
     483
     484        // After widgets_init(), get_settings() should create the widget option.
     485        $never_used = get_option( 'widget_nav_menu' );
     486        $this->assertEquals( 1, $never_used['_multiwidget'] );
     487        $this->assertArrayNotHasKey( 0, $never_used );
    478488    }
    479489
Note: See TracChangeset for help on using the changeset viewer.