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
This commit is contained in:
Scott Taylor 2015-10-13 01:13:24 +00:00
parent a31d7e37dc
commit e7c2544a89
2 changed files with 8 additions and 3 deletions

View File

@ -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 ) ) {

View File

@ -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.