pre_site_option_{$option} WordPress Filter Hook

The pre_site_option_{$option} hook is invoked before a given site option is retrieved. This hook allows you to short-circuit the default logic for retrieving a given site option, and instead provide your own value. This can be useful if you need to dynamically generate a value for a site option, or if you want to override the value of an option set by a plugin or theme. To use this hook, you must first check if the option you're interested in has been set by calling the get_site_option() function. If the function returns false, you can then call the set_site_option() function to set the value of the option. Keep in mind that this hook will only be invoked when the get_site_option() function is called. If you need to override the value of an option set by a plugin or theme, you'll need to use the pre_option_{$option} hook instead.

apply_filters( "pre_site_option_{$option}", mixed $pre_option, string $option, int $network_id, mixed $default ) #

Filters the value of an existing network option before it is retrieved.


Description

The dynamic portion of the hook name, $option, refers to the option name.

Returning a truthy value from the filter will effectively short-circuit retrieval and return the passed value instead.


Top ↑

Parameters

$pre_option

(mixed)The value to return instead of the option value. This differs from $default, 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).

$option

(string)Option name.

$network_id

(int)ID of the network.

$default

(mixed)The fallback value to return if the option does not exist. Default false.


Top ↑

Source

File: wp-includes/option.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
4.9.0The $default parameter was added.
4.7.0The $network_id parameter was added.
4.4.0The $option parameter was added.
3.0.0
2.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More