A WordPress-centric search engine for devs and theme authors



get_id_from_blogname ›

Since4.7.0
Deprecatedn/a
get_id_from_blogname ( $slug )
Parameters:
  • (string) $slug A site's slug.
    Required: Yes
Returns:
  • (int|null) The site ID, or null if no site is found for the given slug.
Defined at:
Codex:
Change Log:
  • MU

Retrieves a sites ID given its (subdomain or directory) slug.



Source

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,
		)
	);

	if ( empty( $site_ids ) ) {
		return null;
	}

	return array_shift( $site_ids );
}