Make WordPress Core

Changeset 14515


Ignore:
Timestamp:
05/08/2010 06:05:16 PM (14 years ago)
Author:
wpmuguru
Message:

consistency & simplicity in get_option(), see #12140

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r14510 r14515  
    311311        return false;
    312312
    313     // prevent non-existent options from triggering multiple queries
    314     if ( defined( 'WP_INSTALLING' ) && is_multisite() ) {
    315         $notoptions = array();
    316     } else {
     313    if ( ! defined( 'WP_INSTALLING' ) ) {
     314        // prevent non-existent options from triggering multiple queries
    317315        $notoptions = wp_cache_get( 'notoptions', 'options' );
    318316        if ( isset( $notoptions[$option] ) )
    319317            return $default;
    320     }
    321 
    322     if ( ! defined( 'WP_INSTALLING' ) ) {
     318
    323319        $alloptions = wp_load_alloptions();
    324     }
    325 
    326     if ( isset( $alloptions[$option] ) ) {
    327         $value = $alloptions[$option];
    328     } else {
    329         $value = wp_cache_get( $option, 'options' );
    330 
    331         if ( false === $value ) {
    332             if ( defined( 'WP_INSTALLING' ) )
    333                 $suppress = $wpdb->suppress_errors();
    334             $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
    335             if ( defined( 'WP_INSTALLING' ) )
    336                 $wpdb->suppress_errors( $suppress );
    337 
    338             // Has to be get_row instead of get_var because of funkiness with 0, false, null values
    339             if ( is_object( $row ) ) {
    340                 $value = $row->option_value;
    341                 if ( ! defined( 'WP_INSTALLING' ) )
     320
     321        if ( isset( $alloptions[$option] ) ) {
     322            $value = $alloptions[$option];
     323        } else {
     324            $value = wp_cache_get( $option, 'options' );
     325
     326            if ( false === $value ) {
     327                $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
     328
     329                // Has to be get_row instead of get_var because of funkiness with 0, false, null values
     330                if ( is_object( $row ) ) {
     331                    $value = $row->option_value;
    342332                    wp_cache_add( $option, $value, 'options' );
    343             } else { // option does not exist, so we must cache its non-existence
    344                 $notoptions[$option] = true;
    345                 wp_cache_set( 'notoptions', $notoptions, 'options' );
    346                 return $default;
     333                } else { // option does not exist, so we must cache its non-existence
     334                    $notoptions[$option] = true;
     335                    wp_cache_set( 'notoptions', $notoptions, 'options' );
     336                    return $default;
     337                }
    347338            }
    348339        }
     340    } else {
     341        $suppress = $wpdb->suppress_errors();
     342        $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
     343        $wpdb->suppress_errors( $suppress );
     344        if ( is_object( $row ) )
     345            $value = $row->option_value;
     346        else
     347            return $default;
    349348    }
    350349
Note: See TracChangeset for help on using the changeset viewer.