WordPress.org

Make WordPress Core

Changeset 21315


Ignore:
Timestamp:
07/24/12 15:13:46 (21 months ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r21311 r21315  
    12251225    // any settings errors you want to show by default. 
    12261226    if ( $sanitize ) 
    1227         sanitize_option( $setting, get_option($setting)); 
     1227        sanitize_option( $setting, get_option( $setting ) ); 
    12281228 
    12291229    // If settings were passed back from options.php then use them 
    1230     // Ignore transients if $sanitize is true, we don't want the old values anyway 
    1231     if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) { 
    1232         $settings_errors = get_transient('settings_errors'); 
    1233         delete_transient('settings_errors'); 
    1234     // Otherwise check global in case validation has been run on this pageload 
    1235     } elseif ( count( $wp_settings_errors ) ) { 
    1236         $settings_errors = $wp_settings_errors; 
    1237     } else { 
    1238         return; 
     1230    if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { 
     1231        $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) ); 
     1232        delete_transient( 'settings_errors' ); 
     1233    } 
     1234 
     1235    // Check global in case errors have been added on this pageload 
     1236    if ( ! count( $wp_settings_errors ) ) { 
     1237        return array(); 
    12391238    } 
    12401239 
    12411240    // Filter the results to those of a specific setting if one was set 
    12421241    if ( $setting ) { 
    1243         foreach ( (array) $settings_errors as $key => $details ) 
    1244             if ( $setting != $details['setting'] ) 
    1245                 unset( $settings_errors[$key] ); 
    1246     } 
    1247     return $settings_errors; 
     1242        foreach ( (array) $wp_settings_errors as $key => $details ) { 
     1243            debug_log( $details['setting'] ); 
     1244            if ( $setting == $details['setting'] ) 
     1245                $setting_errors[] = $wp_settings_errors[$key]; 
     1246        } 
     1247        return $setting_errors; 
     1248    } 
     1249 
     1250    return $wp_settings_errors; 
    12481251} 
    12491252 
     
    12771280    $settings_errors = get_settings_errors( $setting, $sanitize ); 
    12781281 
    1279     if ( ! is_array( $settings_errors ) ) 
     1282    if ( empty( $settings_errors ) ) 
    12801283        return; 
    12811284 
Note: See TracChangeset for help on using the changeset viewer.