get_id_from_blogname( string $slug )
Retrieves a sites ID given its (subdomain or directory) slug.
Description Description
Parameters Parameters
- $slug
-
(string) (Required) A site's slug.
Return Return
(int|null) The site ID, or null if no site is found for the given slug.
Source Source
File: wp-includes/ms-blogs.php
function get_id_from_blogname( $slug ) { $current_network = get_network(); $slug = trim( $slug, '/' ); if ( is_subdomain_install() ) { $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain ); $path = $current_network->path; } else { $domain = $current_network->domain; $path = $current_network->path . $slug . '/'; } $site_ids = get_sites( array( 'number' => 1, 'fields' => 'ids', 'domain' => $domain, 'path' => $path, 'update_site_meta_cache' => false, ) ); if ( empty( $site_ids ) ) { return null; } return array_shift( $site_ids ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
MU (3.0.0) | MU (3.0.0) |
4.7.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Getting id of a blog by name ($slug)
Switching blogs based on the blogs name ($slug)