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/src/wp-includes/class-wp-widget.php

    r34782 r35100  
    540540        $settings = get_option( $this->option_name );
    541541
    542         if ( false === $settings && isset( $this->alt_option_name ) ) {
    543             $settings = get_option( $this->alt_option_name );
     542        if ( false === $settings ) {
     543            if ( isset( $this->alt_option_name ) ) {
     544                $settings = get_option( $this->alt_option_name );
     545            } else {
     546                // Save an option so it can be autoloaded next time.
     547                $this->save_settings( array() );
     548            }
    544549        }
    545550
Note: See TracChangeset for help on using the changeset viewer.