network_home_url( string $path = '', string|null $scheme = null ): string
- Since
- 3.0.0
- Source
wp-includes/link-template.php:3784
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
- Scaling
- Constant
- Instructions
- 10–43
- Plugin surface
- 1 hook
- Called by
- 12
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 51.
Third-party callbacks on 'network_home_url' run inside this call, and their cost is not bounded by anything here.
12 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 · 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.
| When | Instructions | Calls it makes |
|---|---|---|
!is_multisite() | 10 | is_multisite(), home_url() |
is_multisite() && $scheme && $scheme === "relative" | 23–25 | is_multisite(), get_network(), apply_filters() |
is_multisite() && !$scheme && $scheme === "relative" | 28–31 | is_multisite(), get_network(), is_ssl(), apply_filters() |
is_multisite() && $scheme && $scheme !== "relative" | 30–32 | is_multisite(), get_network(), set_url_scheme(), apply_filters() |
is_multisite() && $scheme && $scheme === "relative" && is_string($path) | 30 | is_multisite(), get_network(), ltrim(), apply_filters() |
is_multisite() && !$scheme && $scheme !== "relative" | 35–38 | is_multisite(), get_network(), is_ssl(), set_url_scheme(), apply_filters() |
is_multisite() && !$scheme && $scheme === "relative" && is_string($path) | 35–36 | is_multisite(), get_network(), is_ssl(), ltrim(), apply_filters() |
is_multisite() && $scheme && $scheme !== "relative" && is_string($path) | 37 | is_multisite(), get_network(), set_url_scheme(), ltrim(), apply_filters() |
is_multisite() && !$scheme && $scheme !== "relative" && is_string($path) | 42–43 | is_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:
Uses · 6
- is_multisite()Determines whether Multisite is enabled.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- get_network()Retrieves network data given a network ID or network object.
- is_ssl()Determines if SSL is used.
- 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 · 12
- WP_Automatic_Updater::send_debug_email()Prepares and sends an email of a full log of background update results, useful for debugging and geekery.
- get_blogaddress_by_name()Gets a full site URL, given a site name.
- maybe_redirect_404()Corrects 404 redirects when NOBLOGREDIRECT is defined.
- update_network_option_new_admin_email()Sends a confirmation request email when a change of network admin email address is attempted.
- wp_install_defaults()Creates the initial content for a newly-installed site.
- wp_mail()Sends an email, similar to PHP's mail function.
- wp_notify_postauthor()Notifies an author (and/or others) of a comment/trackback/pingback on a post.
- 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.
- wpmu_signup_user_notification()Sends a confirmation request email to a user when they sign up for a new user account (without signing up for a site at the same time). The user account will not become active until the confirmation link is clicked.
- wpmu_welcome_notification()Notifies the site administrator that their site activation was successful.
- wpmu_welcome_user_notification()Notifies a user that their account activation has been successful.
- wxr_site_url()Returns the URL of the site.
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.
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.