consistency & simplicity in get_option(), see #12140

git-svn-id: http://svn.automattic.com/wordpress/trunk@14515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
wpmuguru 2010-05-08 18:05:16 +00:00
parent 235fc1680b
commit 54222465f0
1 changed files with 24 additions and 25 deletions

View File

@ -310,42 +310,41 @@ function get_option( $option, $default = false ) {
if ( defined( 'WP_SETUP_CONFIG' ) ) if ( defined( 'WP_SETUP_CONFIG' ) )
return false; return false;
// prevent non-existent options from triggering multiple queries if ( ! defined( 'WP_INSTALLING' ) ) {
if ( defined( 'WP_INSTALLING' ) && is_multisite() ) { // prevent non-existent options from triggering multiple queries
$notoptions = array();
} else {
$notoptions = wp_cache_get( 'notoptions', 'options' ); $notoptions = wp_cache_get( 'notoptions', 'options' );
if ( isset( $notoptions[$option] ) ) if ( isset( $notoptions[$option] ) )
return $default; return $default;
}
if ( ! defined( 'WP_INSTALLING' ) ) {
$alloptions = wp_load_alloptions(); $alloptions = wp_load_alloptions();
}
if ( isset( $alloptions[$option] ) ) { if ( isset( $alloptions[$option] ) ) {
$value = $alloptions[$option]; $value = $alloptions[$option];
} else { } else {
$value = wp_cache_get( $option, 'options' ); $value = wp_cache_get( $option, 'options' );
if ( false === $value ) { if ( false === $value ) {
if ( defined( 'WP_INSTALLING' ) ) $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
$suppress = $wpdb->suppress_errors();
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
if ( defined( 'WP_INSTALLING' ) )
$wpdb->suppress_errors( $suppress );
// Has to be get_row instead of get_var because of funkiness with 0, false, null values // Has to be get_row instead of get_var because of funkiness with 0, false, null values
if ( is_object( $row ) ) { if ( is_object( $row ) ) {
$value = $row->option_value; $value = $row->option_value;
if ( ! defined( 'WP_INSTALLING' ) )
wp_cache_add( $option, $value, 'options' ); wp_cache_add( $option, $value, 'options' );
} else { // option does not exist, so we must cache its non-existence } else { // option does not exist, so we must cache its non-existence
$notoptions[$option] = true; $notoptions[$option] = true;
wp_cache_set( 'notoptions', $notoptions, 'options' ); wp_cache_set( 'notoptions', $notoptions, 'options' );
return $default; return $default;
}
} }
} }
} else {
$suppress = $wpdb->suppress_errors();
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
$wpdb->suppress_errors( $suppress );
if ( is_object( $row ) )
$value = $row->option_value;
else
return $default;
} }
// If home is not set use siteurl. // If home is not set use siteurl.