network_site_url( string $path = '', string|null $scheme = null ): string
- Since
- 3.0.0
- Source
wp-includes/link-template.php:3739
Description
Returns the site URL with the appropriate protocol, 'https' if 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 site URL. Default empty.Default:
'' $schemestring|nulloptional- Scheme to give the site URL context. Accepts 'http', 'https', or 'relative'. Default null.Default:
null
Return value
string- Site URL link with optional path appended.
Performance profile
How much work a call to network_site_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
- Scaling
- Constant
- Instructions
- 10–34
- Plugin surface
- 1 hook
- Called by
- 8
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 41.
Third-party callbacks on 'network_site_url' run inside this call, and their cost is not bounded by anything here.
8 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_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 · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost network_site_url() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_multisite() | 10 | is_multisite(), site_url() |
is_multisite() && $scheme === "relative" | 20–22 | is_multisite(), get_network(), apply_filters() |
is_multisite() && $scheme !== "relative" | 27–29 | is_multisite(), get_network(), set_url_scheme(), apply_filters() |
is_multisite() && $scheme === "relative" && is_string($path) | 27 | is_multisite(), get_network(), ltrim(), apply_filters() |
is_multisite() && $scheme !== "relative" && is_string($path) | 34 | is_multisite(), get_network(), 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: 41 instructions, 10–34 executed per call, 4 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_site_url() runs, in this order:
Uses · 5
- is_multisite()Determines whether Multisite is enabled.
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- get_network()Retrieves network data given a network ID or network object.
- set_url_scheme()Sets the scheme for a URL.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 8
- network_admin_url()Retrieves the URL to the admin area for the network.
- redirect_canonical()Redirects incoming links to the proper URL based on the site url.
- retrieve_password()Handles sending a password retrieval email to a user.
- user_admin_url()Retrieves the URL to the admin area for the current user.
- wp_lostpassword_url()Returns the URL that allows the user to reset the lost password.
- wp_new_user_notification()Emails login credentials to a newly-registered user.
- wp_version_check()Checks WordPress version against the newest version.
- wpmu_signup_blog_notification()Sends a confirmation request email to a user when they sign up for a new site. The new site will not become active until the confirmation link is clicked.
Source code
function network_site_url( $path = '', $scheme = null ) { if ( ! is_multisite() ) { return site_url( $path, $scheme ); } $current_network = get_network(); 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 site URL. * * @since 3.0.0 * * @param string $url The complete network site URL including scheme and path. * @param string $path Path relative to the network site URL. Blank string if * no path is specified. * @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https', * 'relative' or null. */ return apply_filters( 'network_site_url', $url, $path, $scheme );}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.