pre_option
Filter HookDescription
Filters the value of all existing options before it is retrieved. Returning a truthy value from the filter will effectively short-circuit retrieval and return the passed value instead.Hook Information
File Location |
wp-includes/option.php
View on GitHub
|
Hook Type | Filter |
Line Number | 150 |
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
|
Name of the option. |
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
add_filter('pre_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:150
- How this hook is used in WordPress core
<?php
145 * Default false (to skip past the short-circuit).
146 * @param string $option Name of the option.
147 * @param mixed $default_value The fallback value to return if the option does not exist.
148 * Default false.
149 */
150 $pre = apply_filters( 'pre_option', $pre, $option, $default_value );
151
152 if ( false !== $pre ) {
153 return $pre;
154 }
155
PHP Documentation
<?php
/**
* Filters the value of all existing options before it is retrieved.
*
* Returning a truthy value from the filter will effectively short-circuit retrieval
* and return the passed value instead.
*
* @since 6.1.0
*
* @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 Name of the option.
* @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.