wppaste
WordPress

network_home_url( string $path = '', string|null $scheme = null ): string

Since
3.0.0
Source
wp-includes/link-template.php:3784
Retrieves the home URL for the current network.

Description

Returns the home URL with the appropriate protocol, 'https' is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is overridden.

Compatibility

WordPress
since 3.0.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

$pathstringoptional
Path relative to the home URL. Default empty.Default: ''
$schemestring|nulloptional
Scheme to give the home URL context. Accepts 'http', 'https', or 'relative'. Default null.Default: null

Return value

string
Home URL link with optional path appended.

Performance profile

How much work a call to network_home_url() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
10–43

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

Plugin surface
1 hook

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

Called by
12

12 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 9 distinct outcomes

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

WhenInstructionsCalls it makes
!is_multisite()10is_multisite(), home_url()
is_multisite() && $scheme && $scheme === "relative"23–25is_multisite(), get_network(), apply_filters()
is_multisite() && !$scheme && $scheme === "relative"28–31is_multisite(), get_network(), is_ssl(), apply_filters()
is_multisite() && $scheme && $scheme !== "relative"30–32is_multisite(), get_network(), set_url_scheme(), apply_filters()
is_multisite() && $scheme && $scheme === "relative" && is_string($path)30is_multisite(), get_network(), ltrim(), apply_filters()
is_multisite() && !$scheme && $scheme !== "relative"35–38is_multisite(), get_network(), is_ssl(), set_url_scheme(), apply_filters()
is_multisite() && !$scheme && $scheme === "relative" && is_string($path)35–36is_multisite(), get_network(), is_ssl(), ltrim(), apply_filters()
is_multisite() && $scheme && $scheme !== "relative" && is_string($path)37is_multisite(), get_network(), set_url_scheme(), ltrim(), apply_filters()
is_multisite() && !$scheme && $scheme !== "relative" && is_string($path)42–43is_multisite(), get_network(), is_ssl(), set_url_scheme(), ltrim(), apply_filters()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 51 instructions, 10–43 executed per call, 6 branches. The work does not change between versions.

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 · 1

One hook fires while network_home_url() runs, in this order:

  1. apply_filters( network_home_url )filterline 3817 (+33 into the body)

    Filters the network home URL.

Uses · 6

Used by · 12

Source code

function network_home_url( $path = '', $scheme = null ) {	if ( ! is_multisite() ) {		return home_url( $path, $scheme );	} 	$current_network = get_network();	$orig_scheme     = $scheme; 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {		$scheme = is_ssl() ? 'https' : 'http';	} 	if ( 'relative' === $scheme ) {		$url = $current_network->path;	} else {		$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );	} 	if ( $path && is_string( $path ) ) {		$url .= ltrim( $path, '/' );	} 	/**	 * Filters the network home URL.	 *	 * @since 3.0.0	 *	 * @param string      $url         The complete network home URL including scheme and path.	 * @param string      $path        Path relative to the network home URL. Blank string	 *                                 if no path is specified.	 * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',	 *                                 'relative' or null.	 */	return apply_filters( 'network_home_url', $url, $path, $orig_scheme );}

Changelog

Introduced in 3.0.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.9.7 tag, from src/wp-includes/link-template.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.