Please can someone help me create a data validation function (or seperate functions) for my theme customizer (code shown below).
I am storing my options in a single, serialised array and would like to apply the following validation:
Text field - apply wp_filter_nohtml_kses()
Radio and Select fields - Ensure that the value saved matches one of my pre-defined values
Checkbox - Check for either Null or "1"
Thank you
function mytheme_customizer( $wp_customize ) {
// Remove unwanted sections
$wp_customize->remove_section('static_front_page');
$wp_customize->remove_section('colors');
// Logo (Radio control)
$wp_customize->add_section(
'logo', array(
'title'=>__('Logo Placement','mytheme'),
'priority'=> 20,
)
);
$wp_customize->add_setting(
'mytheme_options[logo]', array(
'default' => 'left',
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'refresh',
//'sanitize_callback' => '???'
)
);
$wp_customize->add_control(
'logo_control', array(
'label' => __( 'Choose an area', 'mytheme' ),
'section' => 'logo',
'settings' => 'mytheme_options[logo]',
'type' => 'radio',
'choices' => array(
'left' => 'Left',
'right' => 'Right',
'center' => 'Center',
),
)
);
// Skin (Select Control)
$wp_customize->add_section(
'skin', array(
'title'=>__('Theme Skin','mytheme'),
'priority'=> 25,
)
);
$wp_customize->add_setting(
'mytheme_options[skin]', array(
'default' => 'red',
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'refresh',
//'sanitize_callback' => '???'
)
);
$wp_customize->add_control(
'skin_control', array(
'label' => __( 'Theme skin', 'mytheme' ),
'section' => 'skin',
'settings' => 'mytheme_options[skin]',
'type' => 'select',
'choices' => array(
'' => 'None',
'red' => 'Red',
'green' => 'Green',
),
)
);
// Footer (Text Control)
$wp_customize->add_section(
'footer', array(
'title'=>__('Footer Text','mytheme'),
'priority'=>30,
)
);
$wp_customize->add_setting(
'mytheme_options[footer]', array(
'default' => '',
'type'=>'option',
'capability'=>'edit_theme_options',
'transport'=>'refresh',
//'sanitize_callback' => '???',
)
);
$wp_customize->add_control(
'footer_control', array(
'label'=>__('Enter Footer Text', 'mytheme'),
'section'=>'footer',
'settings'=>'mytheme_options[footer]',
'type'=>'text',
)
);
// Copyright (Checkbox Control)
$wp_customize->add_section(
'copyright', array(
'title'=>__('Copyright Notice','mytheme'),
'priority'=> 35,
)
);
$wp_customize->add_setting(
'mytheme_options[copyright]', array(
'default' => '1',
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'refresh',
//'sanitize_callback' => '???'
)
);
$wp_customize->add_control(
'copyright_control', array(
'label' => __( 'Show Copyright Notice?', 'mytheme' ),
'section' => 'copyright',
'settings' => 'mytheme_options[copyright]',
'type' => 'checkbox',
)
);
}
add_action( 'customize_register', 'mytheme_customizer' );