Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_blog_option [ WordPress Function ]

get_blog_option ( $blog_id, $setting, $default = false )
Parameters:
  • (int) $blog_id Optional. Blog ID, can be null to refer to the current blog.
  • (string) $setting Name of option to retrieve. Should already be SQL-escaped.
  • (string) $default (optional) Default value returned if option not found.
Uses:
Returns:
  • (mixed) Value set for the option.
Defined at:



Retrieve option value based on setting name and blog_id.

If the option does not exist or does not have a value, then the return value will be false. This is useful to check whether you need to install an option and is commonly used during installation of plugin options and to test whether upgrading is required.

There is a filter called 'blog_option_$option' with the $option being replaced with the option name. The filter takes two parameters. $value and $blog_id. It returns $value. The 'option_$option' filter in get_option() is not called.

Source


<?php
function get_blog_option$blog_id$setting$default false ) {
    global 
$wpdb;

    if ( 
null === $blog_id )
        
$blog_id $wpdb->blogid;

    
$key $blog_id '-' $setting '-blog_option';
    
$value wp_cache_get$key'site-options' );
    if ( 
$value == null ) {
        if ( 
$blog_id == $wpdb->blogid ) {
            
$value get_option$setting$default );
            
$notoptions wp_cache_get'notoptions''options' );
            if ( isset( 
$notoptions[$setting] ) ) {
                
wp_cache_set$key'noop''site-options' );
                
$value $default;
            } elseif ( 
$value == false ) {
                
wp_cache_set$key'falsevalue''site-options' );
            } else {
                
wp_cache_set$key$value'site-options' );
            }
            return 
apply_filters'blog_option_' $setting$value$blog_id );
        } else {
            
$blog_prefix $wpdb->get_blog_prefix$blog_id );
            
$row $wpdb->get_row$wpdb->prepare"SELECT * FROM {$blog_prefix}options WHERE option_name = %s"$setting ) );
            if ( 
is_object$row ) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
                
$value $row->option_value;
                if ( 
$value == false )
                    
wp_cache_set$key'falsevalue''site-options' );
                else
                    
wp_cache_set$key$value'site-options' );
            } else { 
// option does not exist, so we must cache its non-existence
                
wp_cache_set$key'noop''site-options' );
                
$value $default;
            }
        }
    } elseif ( 
$value == 'noop' ) {
        
$value $default;
    } elseif ( 
$value == 'falsevalue' ) {
        
$value false;
    }
    
// If home is not set use siteurl.
    
if ( 'home' == $setting && '' == $value )
        return 
get_blog_option$blog_id'siteurl' );

    if ( 
'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
        
$value untrailingslashit$value );

    return 
apply_filters'blog_option_' $settingmaybe_unserialize$value ), $blog_id );
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics