wppaste
WordPress

ms_load_current_site_and_network( string $domain, string $path, bool $subdomain = false ): bool|string

Since
4.6.0
Source
wp-includes/ms-load.php:297
Identifies the network and site of a requested domain and path and populates the corresponding network and site global objects as part of the multisite bootstrap process.

Description

Prior to 4.6.0, this was a procedural block in ms-settings.php. It was wrapped into a function to facilitate unit tests. It should not be used outside of core.

Usually, it's easier to query the site first, which then declares its network.
In limited situations, we either can or must find the network first.

If a network and site are found, a true response will be returned so that the request can continue.

If neither a network or site is found, false or a URL string will be returned so that either an error can be shown or a redirect can occur.

Compatibility

WordPress
since 4.6.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$domainstring
The requested domain.
$pathstring
The requested path.
$subdomainbooloptional
Whether a subdomain (true) or subdirectory (false) configuration.
Default false.Default: false

Return value

bool|string
True if bootstrap successfully populated $current_blog and $current_site.
False if bootstrap could not be properly completed.
Redirect URL if parts exist, but the request as a whole can not be fulfilled.

Performance profile

How much work a call to ms_load_current_site_and_network() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Only touches the object cache, via wp_cache_get().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
24–114

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 271.

Plugin surface
2 hooks

Third-party callbacks on 'ms_network_not_found', 'ms_site_not_found' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • cacheobject cachewp_cache_get()called directly
  • hookthird-party callbacksdo_action()called directly

What one call costs · 241 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost ms_load_current_site_and_network() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always24–26wp_cache_get(), do_action()
empty($networks)24–26wp_cache_get(), get_networks()
empty($current_site)30–40get_site_by_path(), ::WP_Network(), do_action()
empty($current_site)30–32wp_cache_get(), ::WP_Network(), do_action()
!empty($current_site) && !empty($current_blog)31–41get_site_by_path(), ::WP_Network()
!empty($networks)33–35wp_cache_get(), get_networks(), do_action()
!empty($current_site)34–51get_site_by_path(), ::WP_Network(), wp_installing()
$path === false36–43wp_cache_get(), get_site_by_path(), do_action()
!empty($current_site) && $path === false && !empty($current_blog)37–44wp_cache_get(), get_site_by_path()
!empty($current_blog)38–48get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($networks) && empty($current_site)39–41wp_cache_get(), get_networks(), ::WP_Network(), do_action()
!empty($current_site) && $path === false40–54wp_cache_get(), get_site_by_path(), wp_installing()
229 further outcomes, up to 114 instructions
always41–58get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
empty($current_site)41–46get_site_by_path(), ::WP_Network(), ::WP_Network(), do_action()
!defined('DOMAIN_CURRENT_SITE')41wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), do_action()
!empty($current_site) && !empty($current_blog)42–47get_site_by_path(), ::WP_Network(), ::WP_Network()
$path !== false42–49wp_cache_get(), substr_count(), get_site_by_path(), do_action()
$path === false42–49wp_cache_get(), ::WP_Network(), get_site_by_path(), do_action()
!empty($current_site) && $path !== false && !empty($current_blog)43–50wp_cache_get(), substr_count(), get_site_by_path()
$path === false && !empty($current_blog)43–50wp_cache_get(), ::WP_Network(), get_site_by_path()
$path === false && !empty($current_blog)44–51wp_cache_get(), get_site_by_path(), get_main_site_id()
!empty($current_site)45–57get_site_by_path(), ::WP_Network(), ::WP_Network(), wp_installing()
!empty($networks) && $path === false45–52wp_cache_get(), get_networks(), get_site_by_path(), do_action()
!empty($networks) && !empty($current_site) && $path === false && !empty($current_blog)46–53wp_cache_get(), get_networks(), get_site_by_path()
!empty($current_site) && $path !== false46–60wp_cache_get(), substr_count(), get_site_by_path(), wp_installing()
$path === false46–60wp_cache_get(), ::WP_Network(), get_site_by_path(), wp_installing()
$path === false47–61wp_cache_get(), get_site_by_path(), wp_installing(), get_main_site_id()
$path === false47–49wp_cache_get(), get_site_by_path(), ::WP_Network(), do_action()
!defined('DOMAIN_CURRENT_SITE') && empty($current_site)47wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), do_action()
!empty($current_site) && $path === false && !empty($current_blog)48–50wp_cache_get(), get_site_by_path(), ::WP_Network()
$path !== false48–55wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), do_action()
!empty($current_blog)49–54get_site_by_path(), ::WP_Network(), ::WP_Network(), get_main_site_id()
$path !== false && !empty($current_blog)49–56wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path()
!empty($networks) && !empty($current_site) && $path === false49–63wp_cache_get(), get_networks(), get_site_by_path(), wp_installing()
$path !== false && !empty($current_blog)50–57wp_cache_get(), substr_count(), get_site_by_path(), get_main_site_id()
$path === false && !empty($current_blog)50–57wp_cache_get(), ::WP_Network(), get_site_by_path(), get_main_site_id()
!empty($current_site) && $path === false51–60wp_cache_get(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($networks) && $path !== false51–58wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), do_action()
!empty($networks) && $path === false51–58wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), do_action()
!empty($networks) && !empty($current_site) && $path !== false && !empty($current_blog)52–59wp_cache_get(), get_networks(), substr_count(), get_site_by_path()
!empty($networks) && $path === false && !empty($current_blog)52–59wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path()
always52–64get_site_by_path(), ::WP_Network(), ::WP_Network(), wp_installing(), get_main_site_id()
$path !== false52–66wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing()
!empty($current_site)53–66get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!empty($networks) && $path === false && !empty($current_blog)53–60wp_cache_get(), get_networks(), get_site_by_path(), get_main_site_id()
$path !== false53–67wp_cache_get(), substr_count(), get_site_by_path(), wp_installing(), get_main_site_id()
$path !== false53–55wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), do_action()
$path === false53–67wp_cache_get(), ::WP_Network(), get_site_by_path(), wp_installing(), get_main_site_id()
$path === false53–55wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path === false53–58wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), do_action()
!empty($current_site) && $path !== false && !empty($current_blog)54–56wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network()
$path === false && !empty($current_blog)54–56wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network()
!empty($current_site)54–68get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!empty($current_site) && $path === false && !empty($current_blog)54–59wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path()
$path === false && !empty($current_blog)55–57wp_cache_get(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($networks) && !empty($current_site) && $path !== false55–69wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), wp_installing()
!empty($networks) && $path === false55–69wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), wp_installing()
!empty($current_site) && empty($current_blog)56–76get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
$path !== false && !empty($current_blog)56–63wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), get_main_site_id()
!empty($networks) && $path === false56–70wp_cache_get(), get_networks(), get_site_by_path(), wp_installing(), get_main_site_id()
!empty($networks) && $path === false56–58wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), do_action()
!empty($networks) && !empty($current_site) && $path === false && !empty($current_blog)57–59wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network()
!empty($current_site) && $path !== false57–66wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing()
$path === false57–66wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($current_site) && empty($current_blog)57–78get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false57–64wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), do_action()
!empty($current_site) && $path === false57–69wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), wp_installing()
$path === false58–67wp_cache_get(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
!empty($networks) && $path !== false && !empty($current_blog)58–65wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path()
!empty($current_site) && $path === false59–69wp_cache_get(), get_site_by_path(), is_ssl(), do_action()
!empty($networks) && $path !== false && !empty($current_blog)59–66wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), get_main_site_id()
!empty($networks) && $path === false && !empty($current_blog)59–66wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), get_main_site_id()
$path !== false59–73wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), get_main_site_id()
$path !== false59–61wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), do_action()
$path !== false59–66wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path === false59–64wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), do_action()
!empty($current_site) && $path === false60–71wp_cache_get(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
$path !== false && !empty($current_blog)60–62wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network()
!empty($networks) && !empty($current_site) && $path === false60–69wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($current_site) && $path !== false && !empty($current_blog)60–67wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path()
!defined('DOMAIN_CURRENT_SITE') && $path === false && !empty($current_blog)60–65wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path()
$path !== false && !empty($current_blog)61–63wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), get_main_site_id()
$path === false && !empty($current_blog)61–63wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($networks) && $path !== false61–75wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing()
$path === false && !empty($current_blog)61–66wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), get_main_site_id()
!empty($current_site) && $path === false && empty($current_blog)62–79wp_cache_get(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($networks) && $path !== false62–76wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), wp_installing(), get_main_site_id()
!empty($networks) && $path !== false62–64wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), do_action()
!empty($networks) && $path === false62–76wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), wp_installing(), get_main_site_id()
!empty($networks) && $path === false62–64wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), do_action()
!empty($networks) && !empty($current_site) && $path !== false && !empty($current_blog)63–65wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network()
!empty($networks) && $path === false && !empty($current_blog)63–65wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network()
!empty($current_site) && $path === false && empty($current_blog)63–81wp_cache_get(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
$path !== false63–72wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($current_site) && $path !== false63–77wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), wp_installing()
!defined('DOMAIN_CURRENT_SITE') && $path === false63–75wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), wp_installing()
!empty($current_site)64–72get_site_by_path(), ::WP_Network(), ::WP_Network(), is_ssl(), do_action()
!empty($networks) && $path === false && !empty($current_blog)64–66wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), get_main_site_id()
$path !== false64–73wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
$path === false64–73wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
$path === false64–76wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), wp_installing(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && $path === false64wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), do_action()
!empty($current_site) && $path !== false65–75wp_cache_get(), substr_count(), get_site_by_path(), is_ssl(), do_action()
$path === false65–75wp_cache_get(), ::WP_Network(), get_site_by_path(), is_ssl(), do_action()
!empty($current_site)65–74get_site_by_path(), ::WP_Network(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false && !empty($current_blog)65–72wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && !empty($current_site) && $path === false && !empty($current_blog)65wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network()
!defined('DOMAIN_CURRENT_SITE') && $path !== false65–70wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), do_action()
!empty($current_site) && $path !== false66–77wp_cache_get(), substr_count(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
$path === false66–77wp_cache_get(), ::WP_Network(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && !empty($current_site) && $path !== false66–75wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($networks) && $path === false66–75wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && !empty($current_blog)66–71wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path()
!empty($current_site) && empty($current_blog)67–82get_site_by_path(), ::WP_Network(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
$path !== false && !empty($current_blog)67–69wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($networks) && $path === false67–76wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
$path !== false && !empty($current_blog)67–74wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && $path === false && !empty($current_blog)67–72wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), get_main_site_id()
!empty($networks) && !empty($current_site) && $path === false68–78wp_cache_get(), get_networks(), get_site_by_path(), is_ssl(), do_action()
!empty($current_site) && $path !== false && empty($current_blog)68–85wp_cache_get(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
$path === false && empty($current_blog)68–85wp_cache_get(), ::WP_Network(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && empty($current_blog)68–84get_site_by_path(), ::WP_Network(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false68–82wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), get_main_site_id()
!empty($networks) && $path !== false68–70wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), do_action()
!defined('DOMAIN_CURRENT_SITE') && !empty($current_site) && $path === false68–75wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($networks) && !empty($current_site) && $path === false69–80wp_cache_get(), get_networks(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false && !empty($current_blog)69–71wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network()
!empty($current_site) && $path !== false && empty($current_blog)69–87wp_cache_get(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
$path === false && empty($current_blog)69–87wp_cache_get(), ::WP_Network(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false69–81wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing()
!empty($current_site) && $path === false70–75wp_cache_get(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!empty($networks) && $path !== false && !empty($current_blog)70–72wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($networks) && $path === false && !empty($current_blog)70–72wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), get_main_site_id()
$path !== false70–79wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
$path !== false70–84wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), wp_installing(), get_main_site_id()
$path !== false70–72wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path === false70–82wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), wp_installing(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && $path === false70wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), do_action()
!empty($current_site) && $path === false71–77wp_cache_get(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
$path !== false71–81wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), is_ssl(), do_action()
!empty($networks) && !empty($current_site) && $path === false && empty($current_blog)71–88wp_cache_get(), get_networks(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path !== false && !empty($current_blog)71–73wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network()
!defined('DOMAIN_CURRENT_SITE') && $path === false && !empty($current_blog)71wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network()
$path !== false72–83wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && !empty($current_site) && $path === false && empty($current_blog)72–90wp_cache_get(), get_networks(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false72–81wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing()
!defined('DOMAIN_CURRENT_SITE') && $path === false && !empty($current_blog)72wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($current_site) && $path === false && empty($current_blog)73–85wp_cache_get(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($networks) && $path !== false73–82wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
!empty($networks) && $path === false73–82wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && !empty($current_blog)73–78wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), get_main_site_id()
!empty($networks) && !empty($current_site) && $path !== false74–84wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), is_ssl(), do_action()
!empty($networks) && $path === false74–84wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), is_ssl(), do_action()
!empty($current_site) && $path === false && empty($current_blog)74–87wp_cache_get(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
$path !== false && empty($current_blog)74–91wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path !== false74–83wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing()
!defined('DOMAIN_CURRENT_SITE') && $path === false74–81wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($networks) && !empty($current_site) && $path !== false75–86wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path === false75–86wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
$path !== false && empty($current_blog)75–93wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path === false75–82wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
!empty($current_site) && $path !== false76–81wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
$path === false76–81wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!empty($networks) && $path !== false && !empty($current_blog)76–78wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($current_site) && $path === false76–84wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path !== false76–88wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && $path !== false76wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), do_action()
!empty($current_site) && $path !== false77–83wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
$path === false77–83wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && !empty($current_site) && $path !== false && empty($current_blog)77–94wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($networks) && $path === false && empty($current_blog)77–94wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path === false77–86wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && !empty($current_blog)77wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network()
!empty($networks) && !empty($current_site) && $path !== false && empty($current_blog)78–96wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path === false && empty($current_blog)78–96wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
$path !== false && !empty($current_blog)78–80wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && $path === false && !empty($current_blog)78wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($networks) && !empty($current_site) && $path === false79–84wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!empty($current_site) && $path !== false && empty($current_blog)79–91wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
$path === false && empty($current_blog)79–91wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($networks) && $path !== false79–88wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && !empty($current_site) && $path === false && empty($current_blog)79–94wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($networks) && !empty($current_site) && $path === false80–86wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false80–90wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), is_ssl(), do_action()
!empty($current_site) && $path !== false && empty($current_blog)80–93wp_cache_get(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
$path === false && empty($current_blog)80–93wp_cache_get(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($current_site) && $path === false && empty($current_blog)80–96wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false80–87wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing()
!empty($networks) && $path !== false81–92wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
$path !== false81–90wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
!defined('DOMAIN_CURRENT_SITE') && $path === false81–88wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
$path !== false82–87wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!empty($networks) && !empty($current_site) && $path === false && empty($current_blog)82–94wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path !== false82–92wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path === false82–90wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), is_ssl(), do_action()
$path !== false83–89wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && !empty($current_site) && $path === false && empty($current_blog)83–96wp_cache_get(), get_networks(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false && empty($current_blog)83–100wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path !== false83–94wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path === false83–92wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false && empty($current_blog)84–102wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && !empty($current_blog)84wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), get_main_site_id()
!empty($networks) && !empty($current_site) && $path !== false85–90wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!empty($networks) && $path === false85–90wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
$path !== false && empty($current_blog)85–97wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path !== false && empty($current_blog)85–102wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path === false && empty($current_blog)85–100wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($networks) && !empty($current_site) && $path !== false86–92wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path === false86–92wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
$path !== false && empty($current_blog)86–99wp_cache_get(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($current_site) && $path !== false && empty($current_blog)86–104wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path === false && empty($current_blog)86–102wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && !empty($current_site) && $path === false87–90wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path !== false87–94wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), get_main_site_id()
!empty($networks) && !empty($current_site) && $path !== false && empty($current_blog)88–100wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($networks) && $path === false && empty($current_blog)88–100wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && !empty($current_site) && $path === false88–92wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false88–96wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), is_ssl(), do_action()
!empty($networks) && !empty($current_site) && $path !== false && empty($current_blog)89–102wp_cache_get(), get_networks(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path === false && empty($current_blog)89–102wp_cache_get(), get_networks(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false89–98wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && !empty($current_site) && $path === false && empty($current_blog)90–100wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($networks) && $path !== false91–96wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && !empty($current_site) && $path === false && empty($current_blog)91–102wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && empty($current_blog)91–106wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action()
!empty($networks) && $path !== false92–98wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && empty($current_blog)92–108wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($current_site) && $path !== false93–98wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path === false93–96wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!empty($networks) && $path !== false && empty($current_blog)94–106wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path !== false94–100wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path === false94–98wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!empty($networks) && $path !== false && empty($current_blog)95–108wp_cache_get(), get_networks(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!empty($current_site) && $path !== false && empty($current_blog)96–108wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path === false && empty($current_blog)96–106wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!empty($current_site) && $path !== false && empty($current_blog)97–110wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path === false && empty($current_blog)97–108wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false99–102wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path !== false100–104wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), is_ssl(), do_action(), strcasecmp()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && empty($current_blog)102–112wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action()
!defined('DOMAIN_CURRENT_SITE') && $path !== false && empty($current_blog)103–114wp_cache_get(), get_networks(), array_shift(), wp_cache_add(), ::WP_Network(), substr_count(), get_site_by_path(), ::WP_Network(), wp_installing(), is_ssl(), do_action(), strcasecmp()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev27124–11432
8.527124–11432
8.427124–114326 fewer instructions than PHP 8.3
8.327724–11532
8.227724–11532
8.127724–115322 fewer instructions than PHP 7.4
7.427924–11532

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 3

3 hooks fire while ms_load_current_site_and_network() runs, in this order:

  1. do_action( ms_network_not_found )actionline 359 (+62 into the body)

    Fires when a network cannot be found based on the requested domain and path.

  2. do_action( ms_network_not_found )actionline 387 (+90 into the body)

    Fires when a network cannot be found based on the requested domain and path.

  3. do_action( ms_site_not_found )actionline 418 (+121 into the body)

    Fires when a network can be determined but a site cannot.

Uses · 12

Source code

function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {	global $current_site, $current_blog; 	// If the network is defined in wp-config.php, we can simply use that.	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {		$current_site         = new stdClass();		$current_site->id     = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;		$current_site->domain = DOMAIN_CURRENT_SITE;		$current_site->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 ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) {			$current_blog = get_site_by_path( $domain, $path );		} elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) {			/*			 * If the current network has a path and also matches the domain and path of the request,			 * we need to look for a site using the first path segment following the network's path.			 */			$current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) );		} else {			// Otherwise, use the first path segment (as usual).			$current_blog = get_site_by_path( $domain, $path, 1 );		}	} elseif ( ! $subdomain ) {		/*		 * A "subdomain" installation can be re-interpreted to mean "can support any domain".		 * If we're not dealing with one of these installations, then the important part is determining		 * the network first, because we need the network's path to identify any sites.		 */		$current_site = wp_cache_get( 'current_network', 'site-options' );		if ( ! $current_site ) {			// Are there even two networks installed?			$networks = get_networks( array( 'number' => 2 ) );			if ( count( $networks ) === 1 ) {				$current_site = array_shift( $networks );				wp_cache_add( 'current_network', $current_site, 'site-options' );			} elseif ( empty( $networks ) ) {				// A network not found hook should fire here.				return false;			}		} 		if ( empty( $current_site ) ) {			$current_site = WP_Network::get_by_path( $domain, $path, 1 );		} 		if ( empty( $current_site ) ) {			/**			 * Fires when a network cannot be found based on the requested domain and path.			 *			 * At the time of this action, the only recourse is to redirect somewhere			 * and exit. If you want to declare a particular network, do so earlier.			 *			 * @since 4.4.0			 *			 * @param string $domain       The domain used to search for a network.			 * @param string $path         The path used to search for a path.			 */			do_action( 'ms_network_not_found', $domain, $path ); 			return false;		} elseif ( $path === $current_site->path ) {			$current_blog = get_site_by_path( $domain, $path );		} else {			// Search the network path + one more path segment (on top of the network path).			$current_blog = get_site_by_path( $domain, $path, substr_count( $current_site->path, '/' ) );		}	} else {		// Find the site by the domain and at most the first path segment.		$current_blog = get_site_by_path( $domain, $path, 1 );		if ( $current_blog ) {			$current_site = WP_Network::get_instance( $current_blog->site_id ? $current_blog->site_id : 1 );		} else {			// If you don't have a site with the same domain/path as a network, you're pretty screwed, but:			$current_site = WP_Network::get_by_path( $domain, $path, 1 );		}

Changelog

Introduced in 4.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/ms-load.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.