WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/sanitize option $option

Description

sanitize_option_$option is a filter applied to an option value to be cleaned up by the function sanitize_option(). 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.

Usage

# filter existing options
function sanitize_builtin_option($value, $option) {
    //...
}
add_filter('sanitize_option_admin_email', 'sanitize_builtin_option', 10, 2);
add_filter('sanitize_option_new_admin_email', 'sanitize_builtin_option', 10, 2);
//...

# filter your own options
function sanitize_url($value, $option) {
    //...
}
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');

Parameters

$value
(string) (required) The value to be sanitized.
Default: None
$option
(string) (optional) The name of the option.
Default: None

Examples

if (! function_exists('lg')) {
    function lg($x) {
        return log($x) / log(2);
    }
}

function sanitize_blocksize($value) {
    return pow(2, ceil(lg($value)));
}

add_filter('sanitize_option_blocksize', 'sanitize_blocksize');

add_option('blocksize', 200); # 256 gets stored for blocksize

Change Log

  • Since: 2.2.3. Originally, only options not filtered by sanitize_option() were passed through a sanitize_option filter.
  • All options are passed through a filter as of 3.3

Source Files

This filter is applied by sanitize_option in wp-includes/formatting.php

Related

Functions

Filters

See also index of Function Reference and index of Template Tags.
This page is marked as incomplete. You can help Codex by expanding it.