Filter hook 'pre_option_{$option}'

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

View Source

pre_option_{$option}

Filter Hook
Description
Filters the value of an existing 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 132

Hook Parameters

Type Name Description
mixed $pre_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_option(). Default false (to skip past the short-circuit).
string $option Option name.
mixed $default_value The fallback value to return if the option does not exist. Default false.

Usage Examples

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

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

Source Code Context

wp-includes/option.php:132 - How this hook is used in WordPress core
<?php
 127  	 *                              Default false (to skip past the short-circuit).
 128  	 * @param string $option        Option name.
 129  	 * @param mixed  $default_value The fallback value to return if the option does not exist.
 130  	 *                              Default false.
 131  	 */
 132  	$pre = apply_filters( "pre_option_{$option}", false, $option, $default_value );
 133  
 134  	/**
 135  	 * Filters the value of all existing options before it is retrieved.
 136  	 *
 137  	 * Returning a truthy value from the filter will effectively short-circuit retrieval

PHP Documentation

<?php
/**
	 * Filters the value of an existing 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 1.5.0
	 * @since 4.4.0 The `$option` parameter was added.
	 * @since 4.9.0 The `$default_value` parameter was added.
	 *
	 * @param mixed  $pre_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_option().
	 *                              Default false (to skip past the short-circuit).
	 * @param string $option        Option name.
	 * @param mixed  $default_value The fallback value to return if the option does not exist.
	 *                              Default false.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/option.php
Related Hooks

Related hooks will be displayed here in future updates.