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.


git-svn-id: https://develop.svn.wordpress.org/trunk@35100 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-10-13 01:12:12 +00:00
parent 32b604de00
commit d936110f7c
2 changed files with 17 additions and 2 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 ) ) {