From e7c2544a8974810b1c5e5a5a49269c5cb4e30b68 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 13 Oct 2015 01:13:24 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@35100 git-svn-id: http://core.svn.wordpress.org/trunk@35065 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-widget.php | 9 +++++++-- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-widget.php b/wp-includes/class-wp-widget.php index 2ccbbcf937..17f79385ce 100644 --- a/wp-includes/class-wp-widget.php +++ b/wp-includes/class-wp-widget.php @@ -539,8 +539,13 @@ class WP_Widget { $settings = get_option( $this->option_name ); - if ( false === $settings && isset( $this->alt_option_name ) ) { - $settings = get_option( $this->alt_option_name ); + if ( false === $settings ) { + 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() ); + } } if ( ! is_array( $settings ) && ! ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index a9ad00d47c..1035f23057 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-35099'; +$wp_version = '4.4-alpha-35100'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.