get_network_option( int|null $network_id, string $option, mixed $default_value = false ): mixed
- Since
- 4.4.0
- Source
wp-includes/option.php:2001
Parameters
$network_idint|null- ID of the network. Can be null to default to the current network ID.
$optionstring- Name of the option to retrieve. Expected to not be SQL-escaped.
$default_valuemixedoptional- Value to return if the option doesn't exist. Default false.Default:
false
Return
mixed- Value set for the option.
Cost profile
Measured from the compiled opcodes, not from a stopwatch. Every number here is identical on any machine that runs the same PHP version, and every function in core is ranked by these figures.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 8–106
- Plugin surface
- 4 hooks
- Called by
- 12
Reaches the database via ->get_row().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.4, depending on the branch taken. The body compiles to 142.
Third-party callbacks on 'pre_site_option_{$option}', 'pre_site_option', 'default_site_option_{$option}' 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
- optionnetwork option
get_network_option()this function does it - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()called directly - serializeserialisation
maybe_unserialize()called directly - sqldatabase query
->get_row()called directly
Further down the call graph this can also reach 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 · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_network_option() can have, taken from its control-flow graph on PHP 8.4.
| When | Instructions | Calls it makes |
|---|---|---|
!$network_id | 8 | none |
$pre !== false | 28–30 | apply_filters()apply_filters() |
$pre !== false | 31–33 | get_current_network_id()apply_filters()apply_filters() |
$pre === false && is_array($notoptions) && isset($notoptions[$option]) | 45–47 | apply_filters()apply_filters()wp_cache_get()apply_filters() |
$pre === false && is_array($notoptions) && isset($notoptions[$option]) | 48–50 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()apply_filters() |
$pre === false && is_multisite() && isset($value) && $value !== false && is_array($notoptions) | 60–64 | apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()apply_filters() |
$pre === false && !is_multisite() && is_array($notoptions) | 62–66 | apply_filters()apply_filters()wp_cache_get()is_multisite()apply_filters()get_option()apply_filters() |
$pre === false && is_multisite() && isset($value) && $value !== false && is_array($notoptions) | 63–67 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()apply_filters() |
$pre === false && !is_multisite() && is_array($notoptions) | 65–69 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()apply_filters()get_option()apply_filters() |
$pre === false && !is_array($notoptions) && is_multisite() && isset($value) && $value !== false | 66–70 | apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()wp_cache_set()apply_filters() |
$pre === false && !is_array($notoptions) && !is_multisite() | 68–72 | apply_filters()apply_filters()wp_cache_get()is_multisite()apply_filters()get_option()wp_cache_set()apply_filters() |
$pre === false && !is_array($notoptions) && is_multisite() && isset($value) && $value !== false | 69–73 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()wp_cache_set()apply_filters() |
9 further outcomes, up to 106 instructions
$pre === false && !is_array($notoptions) && !is_multisite() | 71–75 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()apply_filters()get_option()wp_cache_set()apply_filters() |
$pre === false && is_multisite() && is_object($row) && is_array($notoptions) | 85–91 | apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()maybe_unserialize()wp_cache_set()apply_filters() |
$pre === false && is_multisite() && is_object($row) && is_array($notoptions) | 88–94 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()maybe_unserialize()wp_cache_set()apply_filters() |
$pre === false && is_multisite() && !is_object($row) && is_array($notoptions) | 90–97 | apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()wp_cache_set()apply_filters()apply_filters() |
$pre === false && !is_array($notoptions) && is_multisite() && is_object($row) | 91–97 | apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()maybe_unserialize()wp_cache_set()wp_cache_set()apply_filters() |
$pre === false && is_multisite() && !is_object($row) && is_array($notoptions) | 93–100 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()wp_cache_set()apply_filters()apply_filters() |
$pre === false && !is_array($notoptions) && is_multisite() && is_object($row) | 94–100 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()maybe_unserialize()wp_cache_set()wp_cache_set()apply_filters() |
$pre === false && !is_array($notoptions) && is_multisite() && !is_object($row) | 96–103 | apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()wp_cache_set()apply_filters()wp_cache_set()apply_filters() |
$pre === false && !is_array($notoptions) && is_multisite() && !is_object($row) | 99–106 | get_current_network_id()apply_filters()apply_filters()wp_cache_get()is_multisite()wp_cache_get()->prepare()->get_row()wp_cache_set()apply_filters()wp_cache_set()apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
7.4 | 144 | 10–108 | 12 | More instructions than PHP 8.4 |
8.1 | 144 | 10–108 | 12 | More instructions than PHP 8.4 |
8.2 | 144 | 10–108 | 12 | More instructions than PHP 8.4 |
8.3 | 144 | 10–108 | 12 | More instructions than PHP 8.4 |
8.4 | 142 | 8–106 | 12 | Compiles to the same instructions |
Oldest PHP that compiles this body: 7.4. An instruction is not a fixed amount of time, so a version with the same count is not necessarily the same speed; what the count rules out is a difference in the work itself.
Hooks fired · 6
6 hooks fire while get_network_option() runs, in this order:
- apply_filters( pre_site_option_{$option} )filterline 2038 (+37 into the body)
Filters the value of an existing network option before it is retrieved.
- apply_filters( pre_site_option )filterline 2057 (+56 into the body)
Filters the value of any existing network option before it is retrieved.
- apply_filters( default_site_option_{$option} )filterline 2083 (+82 into the body)
Filters the value of a specific default network option.
- apply_filters( default_site_option_{$option} )filterline 2088 (+87 into the body)
Filters the value of a specific default network option.
- apply_filters( default_site_option_{$option} )filterline 2111 (+110 into the body)
Filters the value of a specific default network option.
- apply_filters( site_option_{$option} )filterline 2135 (+134 into the body)
Filters the value of an existing network option.
Uses · 7
- get_current_network_id()Retrieves the current network ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- is_multisite()Determines whether Multisite is enabled.
- get_option()Retrieves an option value based on an option name.
- maybe_unserialize()Unserializes data only if it was serialized.
- wp_cache_set()Saves the data to the cache.
Used by · 12
- WP_Application_Passwords::create_new_application_password()Creates a new application password.
- WP_Application_Passwords::is_in_use()Checks if application passwords are being used by the site.
- WP_Network::_set_site_name()Sets the site name assigned to the network if one has not been populated.
- WP_Network::get_main_site_id()Returns the main site ID for the network.
- add_network_option()Adds a new network option.
- get_blog_count()Gets the number of active sites on the installation.
- get_site_option()Retrieve an option value for the current network based on name of option.
- get_user_count()Returns the number of active users in your installation.
- is_site_meta_supported()Determines whether site meta is enabled.
- update_network_option()Updates the value of a network option that was already added.
- wp_initialize_site()Runs the initialization routine for a given site.
- wp_insert_site()Inserts a new site into the database.
Source
function get_network_option( $network_id, $option, $default_value = false ) { global $wpdb; if ( $network_id && ! is_numeric( $network_id ) ) { return false; } $network_id = (int) $network_id; // Fallback to the current network if a network ID is not specified. if ( ! $network_id ) { $network_id = get_current_network_id(); } /** * Filters the value of an existing network option before it is retrieved. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * Returning a value other than false from the filter will short-circuit retrieval * and return that value instead. * * @since 2.9.0 As `pre_site_option_{$key}`. * @since 3.0.0 * @since 4.4.0 The `$option` parameter was added. * @since 4.7.0 The `$network_id` parameter was added. * @since 4.9.0 The `$default_value` parameter was added. * * @param mixed $pre_site_option The value to return instead of the option value. This differs from * `$default_value`, which is used as the fallback value in the event * the option doesn't exist elsewhere in get_network_option(). * Default false (to skip past the short-circuit). * @param string $option Option name. * @param int $network_id ID of the network. * @param mixed $default_value The fallback value to return if the option does not exist. * Default false. */ $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default_value ); /** * Filters the value of any existing network option before it is retrieved. * * Returning a value other than false from the filter will short-circuit retrieval * and return that value instead. * * @since 6.9.0 * * @param mixed $pre_option The value to return instead of the network option value. This differs * from `$default_value`, which is used as the fallback value in the event * the option doesn't exist elsewhere in get_network_option(). * Default false (to skip past the short-circuit). * @param string $option Name of the option. * @param int $network_id ID of the network. * @param mixed $default_value The fallback value to return if the option does not exist. * Default false. */ $pre = apply_filters( 'pre_site_option', $pre, $option, $network_id, $default_value ); if ( false !== $pre ) { return $pre; } // Prevent non-existent options from triggering multiple queries. $notoptions_key = "$network_id:notoptions"; $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { /** * Filters the value of a specific default network option. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * @since 3.4.0 * @since 4.4.0 The `$option` parameter was added. * @since 4.7.0 The `$network_id` parameter was added. * * @param mixed $default_value The value to return if the site option does not exist * in the database. * @param string $option Option name.History
Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$network_id retyped from int to int|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/option.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.