Filter hook 'pre_site_option_{$option}'

in WP Core File wp-includes/option.php at line 2038

View Source

pre_site_option_{$option}

Filter Hook
Description
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.

Hook Information

File Location wp-includes/option.php View on GitHub
Hook Type Filter
Line Number 2038

Hook Parameters

Type Name Description
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).
string $option Option name.
int $network_id ID of the network.
mixed $default_value The fallback value to return if the option does not exist. Default false.

Usage Examples

Basic Usage
<?php
// Hook into pre_site_option_{$option}
add_filter('pre_site_option_{$option}', 'my_custom_filter', 10, 4);

function my_custom_filter($pre_site_option, $option, $network_id, $default_value) {
    // Your custom filtering logic here
    return $pre_site_option;
}

Source Code Context

wp-includes/option.php:2038 - How this hook is used in WordPress core
<?php
2033  	 * @param string $option          Option name.
2034  	 * @param int    $network_id      ID of the network.
2035  	 * @param mixed  $default_value   The fallback value to return if the option does not exist.
2036  	 *                                Default false.
2037  	 */
2038  	$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default_value );
2039  
2040  	if ( false !== $pre ) {
2041  		return $pre;
2042  	}
2043  

PHP Documentation

<?php
/**
	 * 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-includes/option.php
Related Hooks

Related hooks will be displayed here in future updates.