I'm creating a custom settings page for a custom theme however the callbacks for sanatizing the data in the fields are not being called (I put in xdebug breakpoints in them to check).
/**
*------------------------- Admin Page Titles -------------------------
*/
function header_options_text() {
echo '<p>These options affect the Header content.</p>';
}
/**
*------------------------- Header Options -------------------------
*/
function phone_number_input() {
$option = get_option('header_phone');
echo '<input id="header_phone" name="header_phone" size="40" type="text" value="'.$option.'"> </input>';
}
function header_logo_input() {
$option = get_option('header_logo');
echo '<input id="header_logo" name="header_logo" size="40" type="text" value="'.$option.'"> </input>';
}
/**
*------------------------- Header Validation Options -------------------------
*/
function header_phone_validate($input) {
$new_input=trim($input);
if(get_option( 'header_phone' ) === $new_input || !preg_match('/^[\+\d\(\)\- ]*$/', $new_input))
$new_input=get_option( 'header_phone' );
return $new_input;
}
function header_logo_validate($input) {
$new_input=esc_url_raw(trim($input));
if(get_option( 'header_logo' ) === $new_input && !filter_var($new_input, FILTER_VALIDATE_URL))
$new_input=get_option( 'header_logo' );
return $input;
}
/**
*------------------------- Actually create the pages and add to menu -------------------------
*/
add_action( 'admin_menu', 'ec1_admin', 10, 0 );
function ec1_admin() {
add_menu_page( 'EC1 Theme Options', 'EC1 Theme Options', 'manage_options', 'ec1-theme-options', 'ec1_theme_options_page' );
}
function ec1_theme_options_page() {
?>
<div>
<h2>EC1 Theme Options</h2>
<form action="options.php" method="post">
<?php settings_fields('header-options'); ?>
<?php settings_fields('header-logo-options'); ?>
<?php do_settings_sections( 'ec1-theme-options' ); ?>
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</form>
</div>
<?php
}
add_action('admin_init', 'plugin_admin_init');
function plugin_admin_init(){
register_setting( 'header-options', 'header_phone', 'header_phone_validate' );
register_setting( 'header-logo-options', 'header_logo', 'header_logo_validate' );
add_settings_section('header-options-pane', 'Header Options', 'header_options_text', 'ec1-theme-options');
add_settings_field('header_phone', 'Phone Number', 'phone_number_input', 'ec1-theme-options', 'header-options-pane');
add_settings_field('header_logo', 'Header Logo', 'header_logo_input', 'ec1-theme-options', 'header-options-pane');
}
?>