Switch language

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




get_blog_id_from_url [ WordPress Function ]

get_blog_id_from_url ( $domain, $path = '/' )
Parameters:
  • (string) $domain
  • (string) $path Optional. Not required for subdomain installations.
Returns:
  • (int)
Defined at:



Get a blog's numeric ID from its URL.

On a subdirectory installation like example.com/blog1/, $domain will be the root 'example.com' and $path the subdirectory '/blog1/'. With subdomains like blog1.example.com, $domain is 'blog1.example.com' and $path is '/'.

Source


<?php
function get_blog_id_from_url$domain$path '/' ) {
    global 
$wpdb;

    
$domain strtolower$wpdb->escape$domain ) );
    
$path strtolower$wpdb->escape$path ) );
    
$id wp_cache_getmd5$domain $path ), 'blog-id-cache' );

    if ( 
$id == -) { // blog does not exist
        
return 0;
    } elseif ( 
$id ) {
        return (int)
$id;
    }

    
$id $wpdb->get_var"SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" );

    if ( !
$id ) {
        
wp_cache_setmd5$domain $path ), -1'blog-id-cache' );
        return 
false;
    }
    
wp_cache_setmd5$domain $path ), $id'blog-id-cache' );

    return 
$id;
}
?>

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