I'm currently using Ian Stewart's A Sample WordPress Theme Options Page trying to create an inputfield and two textareas.
Probably overlooking something somewhere I seem to be having some difficulties adding the second textarea.
Does someone know what I'm doing wrong perhaps?
Here's the code I'm currently using:
<?php
add_action('admin_init', 'theme_options_init');
add_action('admin_menu', 'theme_options_add_page');
/**
* Init plugin options to white list our options
*/
function theme_options_init() {
register_setting('schema_options', 'schema_theme_options', 'theme_options_validate');
}
/**
* Load up the menu page
*/
function theme_options_add_page() {
add_theme_page(__('Theme Options', 'schema'), __('Theme Options', 'schema'), 'edit_theme_options', 'theme_options', 'theme_options_do_page');
}
/**
* Create the options page
*/
function theme_options_do_page() {
if (!isset($_REQUEST['settings-updated']))
$_REQUEST['settings-updated'] = false;
?>
<div class="wrap">
<?php echo "<h2>" . get_current_theme() . __(' Theme Options', 'schema') . "</h2>"; ?>
<?php if (false !== $_REQUEST['settings-updated']): ?>
<div class="updated fade">
<p><strong><?php _e('Options saved', 'schema'); ?></strong></p>
</div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields('schema_options'); ?>
<?php $options = get_option('schema_theme_options'); ?>
<table class="form-table">
<?php
/**
* A sample text input option
*/
?>
<tr valign="top">
<th scope="row"><?php _e('Some text', 'schema'); ?></th>
<td><input id="schema_theme_options[typekit]" class="regular-text" type="text" name="schema_theme_options[typekit]" value="<?php esc_attr_e($options['typekit']); ?>" />
<label class="description" for="schema_theme_options[typekit]">
<?php _e('Sample text input', 'schema'); ?>
</label></td>
</tr>
<?php
/**
* A sample textarea option
*/
?>
<tr valign="top">
<th scope="row"><?php _e('A textbox', 'schema'); ?></th>
<td><textarea id="schema_theme_options[metadescription]" class="large-text" cols="50" rows="10" name="schema_theme_options[metadescription]"><?php echo esc_textarea($options['metadescription']); ?></textarea>
<label class="description" for="schema_theme_options[metadescription]">
<?php _e('Sample text box', 'schema'); ?>
</label></td>
</tr>
<?php
/**
* A sample textarea option
*/
?>
<tr valign="top">
<th scope="row"><?php _e('A textbox2', 'schema'); ?></th>
<td><textarea id="schema_theme_options[homedescription]" class="large-text" cols="50" rows="10" name="schema_theme_options[homedescription]"><?php echo esc_textarea($options['homedescription']); ?></textarea>
<label class="description" for="schema_theme_options[homedescription]">
<?php _e('Sample tex2t box', 'schema'); ?>
</label></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Options', 'schema'); ?>" />
</p>
</form>
</div>
<?php
}
/**
* Sanitize and validate input. Accepts an array, return a sanitized array.
*/
function theme_options_validate($input) {
// Say our text option must be safe text with no HTML tags
$input['typekit'] = wp_filter_nohtml_kses($input['typekit']);
// Say our textarea option must be safe text with the allowed tags for posts
$input['metadescription'] = wp_filter_post_kses($input['metadescription']);
$input['homedescription'] = wp_filter_post_kses($input['homedescription']);
return $input;
}