Switch language

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




get_blog_details [ WordPress Function ]

get_blog_details ( $fields, $get_all = true )
Parameters:
  • (int|string|array) $fields A blog ID, a blog name, or an array of fields to query against.
  • (bool) $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
Returns:
  • (object) Blog details.
Defined at:



Retrieve the details for a blog from the blogs table and blog options.

Source


<?php
function get_blog_details$fields$get_all true ) {
    global 
$wpdb;

    if ( 
is_array($fields ) ) {
        if ( isset(
$fields['blog_id']) ) {
            
$blog_id $fields['blog_id'];
        } elseif ( isset(
$fields['domain']) && isset($fields['path']) ) {
            
$key md5$fields['domain'] . $fields['path'] );
            
$blog wp_cache_get($key'blog-lookup');
            if ( 
false !== $blog )
                return 
$blog;
            if ( 
substr$fields['domain'], 0) == 'www.' ) {
                
$nowww substr$fields['domain'], );
                
$blog $wpdb->get_row$wpdb->prepare"SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC"$nowww$fields['domain'], $fields['path'] ) );
            } else {
                
$blog $wpdb->get_row$wpdb->prepare"SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s"$fields['domain'], $fields['path'] ) );
            }
            if ( 
$blog ) {
                
wp_cache_set($blog->blog_id 'short'$blog'blog-details');
                
$blog_id $blog->blog_id;
            } else {
                return 
false;
            }
        } elseif ( isset(
$fields['domain']) && is_subdomain_install() ) {
            
$key md5$fields['domain'] );
            
$blog wp_cache_get($key'blog-lookup');
            if ( 
false !== $blog )
                return 
$blog;
            if ( 
substr$fields['domain'], 0) == 'www.' ) {
                
$nowww substr$fields['domain'], );
                
$blog $wpdb->get_row$wpdb->prepare"SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC"$nowww$fields['domain'] ) );
            } else {
                
$blog $wpdb->get_row$wpdb->prepare"SELECT * FROM $wpdb->blogs WHERE domain = %s"$fields['domain'] ) );
            }
            if ( 
$blog ) {
                
wp_cache_set($blog->blog_id 'short'$blog'blog-details');
                
$blog_id $blog->blog_id;
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    } else {
        if ( !
is_numeric$fields ) )
            
$blog_id get_id_from_blogname$fields );
        else
            
$blog_id $fields;
    }

    
$blog_id = (int) $blog_id;

    
$all $get_all == true '' 'short';
    
$details wp_cache_get$blog_id $all'blog-details' );

    if ( 
$details ) {
        if ( ! 
is_object$details ) ) {
            if ( 
$details == -) {
                return 
false;
            } else {
                
// Clear old pre-serialized objects. Cache clients do better with that.
                
wp_cache_delete$blog_id $all'blog-details' );
                unset(
$details);
            }
        } else {
            return 
$details;
        }
    }

    
// Try the other cache.
    
if ( $get_all ) {
        
$details wp_cache_get$blog_id 'short''blog-details' );
    } else {
        
$details wp_cache_get$blog_id'blog-details' );
        
// If short was requested and full cache is set, we can return.
        
if ( $details ) {
            if ( ! 
is_object$details ) ) {
                if ( 
$details == -) {
                    return 
false;
                } else {
                    
// Clear old pre-serialized objects. Cache clients do better with that.
                    
wp_cache_delete$blog_id'blog-details' );
                    unset(
$details);
                }
            } else {
                return 
$details;
            }
        }
    }

    if ( empty(
$details) ) {
        
$details $wpdb->get_row$wpdb->prepare"SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */"$blog_id ) );
        if ( ! 
$details ) {
            
// Set the full cache.
            
wp_cache_set$blog_id, -1'blog-details' );
            return 
false;
        }
    }

    if ( ! 
$get_all ) {
        
wp_cache_set$blog_id $all$details'blog-details' );
        return 
$details;
    }

    
$details->blogname        get_blog_option$blog_id'blogname' );
    
$details->siteurl        get_blog_option$blog_id'siteurl' );
    
$details->post_count    get_blog_option$blog_id'post_count' );

    
$details apply_filters'blog_details'$details );

    
wp_cache_set$blog_id $all$details'blog-details' );

    
$key md5$details->domain $details->path );
    
wp_cache_set$key$details'blog-lookup' );

    return 
$details;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



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