From 2c0f98fe4921f8bcbc6b6a73146a49e2014cce4c Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 24 Jul 2012 15:13:46 +0000 Subject: [PATCH] For get_settings_errors(), make sure errors from transient get added to the global variable and not unset when checking for an error of a specific setting. Also always return an array, as noted in the documentation. Props obenland. fixes #20833 git-svn-id: https://develop.svn.wordpress.org/trunk@21315 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/template.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 1ad997964f..17a4aafeb5 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1224,27 +1224,30 @@ function get_settings_errors( $setting = '', $sanitize = false ) { // This allows the $sanitize_callback from register_setting() to run, adding // any settings errors you want to show by default. if ( $sanitize ) - sanitize_option( $setting, get_option($setting)); + sanitize_option( $setting, get_option( $setting ) ); // If settings were passed back from options.php then use them - // Ignore transients if $sanitize is true, we don't want the old values anyway - if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) { - $settings_errors = get_transient('settings_errors'); - delete_transient('settings_errors'); - // Otherwise check global in case validation has been run on this pageload - } elseif ( count( $wp_settings_errors ) ) { - $settings_errors = $wp_settings_errors; - } else { - return; + if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { + $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) ); + delete_transient( 'settings_errors' ); + } + + // Check global in case errors have been added on this pageload + if ( ! count( $wp_settings_errors ) ) { + return array(); } // Filter the results to those of a specific setting if one was set if ( $setting ) { - foreach ( (array) $settings_errors as $key => $details ) - if ( $setting != $details['setting'] ) - unset( $settings_errors[$key] ); + foreach ( (array) $wp_settings_errors as $key => $details ) { + debug_log( $details['setting'] ); + if ( $setting == $details['setting'] ) + $setting_errors[] = $wp_settings_errors[$key]; + } + return $setting_errors; } - return $settings_errors; + + return $wp_settings_errors; } /** @@ -1276,7 +1279,7 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa $settings_errors = get_settings_errors( $setting, $sanitize ); - if ( ! is_array( $settings_errors ) ) + if ( empty( $settings_errors ) ) return; $output = '';