wppaste
WordPress

get_site_option( string $option, mixed $default_value = false, bool $deprecated = true ): mixed

Since
2.8.0, 4.4.0, 4.4.0
Source
wp-includes/option.php:1934

Fetches a value from the network-wide options table (wp_options on a single site) using $option as the key. Falls back to $default_value when no such option has been saved. The third parameter $deprecated exists only for backward compatibility and has no effect on caching or behavior. Use update_site_option() to write the value this function reads.

Retrieve an option value for the current network based on name of option.

Compatibility

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

$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
$deprecatedbooloptional
Whether to use cache. Multisite only. Always set to true.Default: true

Return value

mixed
Value set for the option.

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Get a custom network-wide setting with a fallback

A plugin stores a support email address as a site option so it can be shared across every site in the network.

$support_email = get_site_option( 'acme_support_email', '[email protected]' );

echo esc_html( $support_email );

On a non-multisite install this reads from wp_options the same way get_option() does.

Show a default value when a site option was never saved

Check for a feature flag that a plugin has not created yet, to confirm the fallback logic before wiring up an admin screen.

$flag = get_site_option( 'acme_beta_features', 'disabled' );

printf( 'Beta features are currently: %s', esc_html( $flag ) );

Common problems and fixes · 3

Why doesn't the third parameter change whether get_site_option uses the cache?

The source hardcodes $deprecated to true and never passes it to get_network_option(). It is kept only so old calls that supplied a third argument don't break.

Why can't I tell if a site option is really false or just missing?

get_site_option() returns $default_value whenever the option row doesn't exist, and that default is false unless you set it otherwise. If you deliberately store the boolean false as the value, it looks identical to "not set". - Pass a distinct sentinel as $default_value, such as a specific string, then compare against it. - Or check existence with a dedicated call before relying on the returned value.

Does get_site_option work on a normal single-site install?

Yes. The function always calls get_network_option( null, $option, $default_value ), and get_network_option() falls back to the regular wp_options table when multisite is not enabled, so you don't need is_multisite() checks around it.

Alternatives and related functions

get_network_option
When you need to target a specific network ID instead of the current one, since get_site_option() always passes null for it.
get_option
When the value is per-site rather than shared across the whole network.
update_site_option
When you need to write or change the value this function reads.
add_site_option
When you want to add a site option only if it does not already exist.

Performance profile

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

Reads stored settings via get_site_option(), cached per request but not free on a cold cache.

Scaling
Constant

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

Instructions
9

Executed per call on PHP 8.5. The body compiles to 9.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
50

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

What it touches

  • optionnetwork optionget_site_option()this function does it
  • hookthird-party callbacksapply_filters()one call below get_site_option()
  • cacheobject cachewp_cache_get()one call below get_site_option()
  • serializeserialisationmaybe_unserialize()one call below get_site_option()

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

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

WhenInstructionsCalls it makes
always9get_network_option()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 9 instructions, 9 executed per call, 0 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.

Uses · 1

Used by · 50

Show all 50

Source code

function get_site_option( $option, $default_value = false, $deprecated = true ) {	return get_network_option( null, $option, $default_value );}

Changelog

Introduced in 2.8.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.

4.4.0
Modified into wrapper for get_network_option()from the docblock
4.4.0
The $use_cache parameter was deprecated.from the docblock
2.8.0
Introduced.from the docblock

About 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.