sanitize_callback
A callback function that sanitizes the value of control before storing it in the database. For additional information about sanitize_callback, please check the official Customizer API.
REMINDER
The sanitize_callback argument is only optional or for custom sanitization purposes only, since each control is already well sanitized.
Attributes
This is the sanitize_callback's comprehensive information.
| Type | Required | Default | Return |
|---|---|---|---|
| callable | no | null | mixed |
Basic Usage
EXAMPLE 1
In this example, the text control's value will be sanitized using the WordPress built-in sanitizer function sanitize_text_field.
// Text Control.
Handy::control( 'text', [
'id' => 'text_id',
'section' => 'layout_section',
'label' => esc_html__( 'Text Control', 'textdomain' ),
'priority' => 1,
'sanitize_callback' => function( $input ) {
// removes all HTML markup, as well extra whitespace.
return sanitize_text_field( $input );
}
]);
EXAMPLE 1
In this example, the URL control's value will be sanitized using the WordPress built-in sanitizer function sanitize_url.
// URL Control.
Handy::control( 'url', [
'id' => 'url_id',
'section' => 'layout_section',
'label' => esc_html__( 'URL Control', 'textdomain' ),
'priority' => 1,
'sanitize_callback' => 'sanitize_url_control_value'
]);
/**
* Custom sanitization. Sanitize a URL.
*
* @param mixed $input Contains the control's value.
* @return mixed
*/
function sanitize_url_control_value( $input ) {
// cleans URL from all invalid characters.
return sanitize_url( $input );
}