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.

Built from https://develop.svn.wordpress.org/trunk@54112


git-svn-id: http://core.svn.wordpress.org/trunk@53671 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-09-09 02:19:10 +00:00
parent 31c90342c9
commit 3c6cad73b2
2 changed files with 9 additions and 5 deletions

View File

@ -612,12 +612,16 @@ class WP_Widget {
$settings = get_option( $this->option_name );
if ( false === $settings ) {
$settings = array();
if ( isset( $this->alt_option_name ) ) {
$settings = get_option( $this->alt_option_name );
} else {
// Save an option so it can be autoloaded next time.
$this->save_settings( array() );
// Get settings from alternative (legacy) option.
$settings = get_option( $this->alt_option_name, array() );
// Delete the alternative (legacy) option as the new option will be created using `$this->option_name`.
delete_option( $this->alt_option_name );
}
// Save an option so it can be autoloaded next time.
$this->save_settings( $settings );
}
if ( ! is_array( $settings ) && ! ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) ) {

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-54111';
$wp_version = '6.1-alpha-54112';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.