Make WordPress Core


Ignore:
Timestamp:
09/09/2022 02:17:33 AM (21 months ago)
Author:
peterwilsoncc
Message:

Widgets: Store default options for uninitialized widgets.

Prevent unnecessary database queries on page load by initializing widget options. On sites with uninitialized widgets, this prevents one or two database queries per uninitialized widget on each page load.

Props Chouby, mvraghavan, costdev, peterwilsoncc, spacedmonkey, mukesh27.
Fixes #54677.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-widget.php

    r52173 r54112  
    613613
    614614        if ( false === $settings ) {
     615            $settings = array();
    615616            if ( isset( $this->alt_option_name ) ) {
    616                 $settings = get_option( $this->alt_option_name );
    617             } else {
    618                 // Save an option so it can be autoloaded next time.
    619                 $this->save_settings( array() );
    620             }
     617                // Get settings from alternative (legacy) option.
     618                $settings = get_option( $this->alt_option_name, array() );
     619
     620                // Delete the alternative (legacy) option as the new option will be created using `$this->option_name`.
     621                delete_option( $this->alt_option_name );
     622            }
     623            // Save an option so it can be autoloaded next time.
     624            $this->save_settings( $settings );
    621625        }
    622626
Note: See TracChangeset for help on using the changeset viewer.