sanitize_option_{$option} WordPress Filter Hook

The sanitize_option_{$option} hook is called when an option is being sanitized. The hook is called with the option name and the option value passed as parameters.

apply_filters( "sanitize_option_{$option}", string $value, string $option, string $original_value ) #

Filters an option value following sanitization.


Parameters

$value

(string)The sanitized option value.

$option

(string)The option name.

$original_value

(string)The original value passed to the function.


Top ↑

More Information

There is one filter per option name; the $option in the filter name stands for the name (e.g. ‘sanitize_option_blogname‘, ‘sanitize_option_siteurl‘). You can use this filter to define a sanitizer for your own options. See the notes for sanitize_option() for a list of existing options.

Filter existing options

add_filter('sanitize_option_admin_email', 'sanitize_builtin_option', 10, 2);
add_filter('sanitize_option_new_admin_email', 'sanitize_builtin_option', 10, 2);

function sanitize_builtin_option($value, $option) {
    //...
}

Filter your own options

add_filter('sanitize_option_feed_url', 'sanitize_url', 10, 2);
add_filter('sanitize_option_wpi_endpoint', 'sanitize_url', 10, 2);
add_filter('sanitize_option_contact_email', 'sanitize_email');

function sanitize_url($value, $option) {
    //...
}

function sanitize_email($value, $option) {
    //...
}

Top ↑

Source

File: wp-includes/formatting.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
4.3.0Added the $original_value parameter.
2.3.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