Switch language

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




wpmu_current_site [ WordPress Function ]

wpmu_current_site ( No parameters )
Access:
  • private
Returns:
  • (object) $current_site object
Defined at:



Sets current_site object.

Source


<?php
function wpmu_current_site() {
    global 
$wpdb$current_site$domain$path$sites$cookie_domain;

    if ( empty( 
$current_site ) )
        
$current_site = new stdClass;

    if ( 
defined'DOMAIN_CURRENT_SITE' ) && defined'PATH_CURRENT_SITE' ) ) {
        
$current_site->id defined'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE 1;
        
$current_site->domain DOMAIN_CURRENT_SITE;
        
$current_site->path   $path PATH_CURRENT_SITE;
        if ( 
defined'BLOG_ID_CURRENT_SITE' ) )
            
$current_site->blog_id BLOG_ID_CURRENT_SITE;
        elseif ( 
defined'BLOGID_CURRENT_SITE' ) ) // deprecated.
            
$current_site->blog_id BLOGID_CURRENT_SITE;
        if ( 
DOMAIN_CURRENT_SITE == $domain )
            
$current_site->cookie_domain $cookie_domain;
        elseif ( 
substr$current_site->domain0) == 'www.' )
            
$current_site->cookie_domain substr$current_site->domain);
        else
            
$current_site->cookie_domain $current_site->domain;

        
wp_load_core_site_options$current_site->id );

        return 
$current_site;
    }

    
$current_site wp_cache_get'current_site''site-options' );
    if ( 
$current_site )
        return 
$current_site;

    
$sites $wpdb->get_results"SELECT * FROM $wpdb->site); // usually only one site
    
if ( == count$sites ) ) {
        
$current_site $sites[0];
        
wp_load_core_site_options$current_site->id );
        
$path $current_site->path;
        
$current_site->blog_id $wpdb->get_var$wpdb->prepare"SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s"$current_site->domain$current_site->path ) );
        
$current_site get_current_site_name$current_site );
        if ( 
substr$current_site->domain0) == 'www.' )
            
$current_site->cookie_domain substr$current_site->domain);
        
wp_cache_set'current_site'$current_site'site-options' );
        return 
$current_site;
    }
    
$path substr$_SERVER'REQUEST_URI' ], 0strpos$_SERVER'REQUEST_URI' ], '/') );

    if ( 
$domain == $cookie_domain )
        
$current_site $wpdb->get_row$wpdb->prepare"SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s"$domain$path ) );
    else
        
$current_site $wpdb->get_row$wpdb->prepare"SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1"$domain$cookie_domain$path ) );

    if ( ! 
$current_site ) {
        if ( 
$domain == $cookie_domain )
            
$current_site $wpdb->get_row$wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'"$domain ) );
        else
            
$current_site $wpdb->get_row$wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1"$domain$cookie_domain$path ) );
    }

    if ( 
$current_site ) {
        
$path $current_site->path;
        
$current_site->cookie_domain $cookie_domain;
        return 
$current_site;
    }

    if ( 
is_subdomain_install() ) {
        
$sitedomain substr$domainstrpos$domain'.' ) );
        
$current_site $wpdb->get_row$wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s"$sitedomain$path) );
        if ( 
$current_site ) {
            
$current_site->cookie_domain $current_site->domain;
            return 
$current_site;
        }

        
$current_site $wpdb->get_row$wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'"$sitedomain) );
    }

    if ( 
$current_site || defined'WP_INSTALLING' ) ) {
        
$path '/';
        return 
$current_site;
    }

    
// Still no dice.
    
wp_load_translations_early();

    if ( 
== count$sites ) )
        
wp_diesprintf__'That site does not exist. Please try <a href="%s">%s</a>.' ), 'http://' $sites[0]->domain $sites[0]->path ) );
    else
        
wp_die__'No site defined on this host. If you are the owner of this site, please check <a href="http://codex.wordpress.org/Debugging_a_WordPress_Network">Debugging a WordPress Network</a> for help.' ) );
}
?>

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