1

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;
}
  • Also on my side there aren't issues, maybe you have a caching plugin activated? – maisdesign Dec 9 '11 at 10:13
1

I checked out the code that you posted and didn't find any issues. I then copied it into my theme's functions.php, it worked for me. Both text areas appear, and data can be saved.

1

Not entirely sure if this would be the best way to answer my own question. As told by @goto10 and @maisdesign there is indeed nothing wrong with the code snippet above.

Above article however uses require_once to load the theme-options.php. Using include_once(get_stylesheet_directory() . '/theme-options.php'); however solved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy