I check the sanity of some settings with sanitize_callback
. It works, but on fail, I want to reset the value do the default one. How can I do that?
$wp_customize->add_setting(
$attribute[0],
array(
"default" => $attribute[1],
"sanitize_callback" => $validate_func,
)
);
EDIT
An example for $validate_func
is kb_validate_url_facebook
which checks if the setting is an URL and if it contains facebook.com.
function kb_validate_url( $url, $valid, $default ) {
if ( $url === "" ) return $default;
$url = strtolower( esc_url_raw( $url ) );
if ( !strpos( $url, $valid ) ) {
if ( $url !== "" ) {
return null;
}
}
return $url;
}
function kb_validate_url_facebook( $url ) {
return kb_validate_url( $url, 'facebook.com', 'www.facebook.com/USERNAME' );
}