On the site I'm currently developing I have created a theme options page (under Appearance). All there is on this page is a text area so the client can add some summary text to appear above their posts.
I am using TinyMCE on this textarea so they can format their text, but if I have TinyMCE enabled the 'Save Options' button doesn't do anything upon clicking it. If I comment out the following lines in my theme-options file to disable TinyMCE, then it saves correctly.
<?php
wp_tiny_mce( false , // true makes the editor "teeny"
array(
"editor_selector" => "large-text"
)
);
?>
Note: The TinyMCE loads and displays correctly - text can be formatted, just not saved.
Any idea what could be causing this?
I am using WordPress 3.2.
Thanks!
Edit: The entire code in my theme-options.php file is as follows
<?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( 'client_options', 'client_theme_options', 'theme_options_validate' );
}
/**
* Load up the menu page
*/
function theme_options_add_page() {
add_theme_page( __( 'Intro/Welcome Text', 'client' ), __( 'Intro/Welcome Text', 'client' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
}
/**
* Create the options page
*/
function theme_options_do_page() {
global $select_options, $radio_options;
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false;
?>
<div class="wrap">
<?php screen_icon(); echo "<h2>" . __( ' Intro/Welcome Text', 'client' ) . "</h2>"; ?>
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e( 'Options saved', 'client' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( 'client_options' ); ?>
<?php $options = get_option( 'client_theme_options' ); ?>
<?php
wp_tiny_mce( true , // true makes the editor "teeny"
array(
"editor_selector" => "large-text"
)
);
?>
<table class="form-table">
<?php
/**
* A sample textarea option
*/
?>
<tr valign="top"><th scope="row"><?php _e( 'Intro/Welcome Text' ); ?></th>
<td>
<textarea id="client_theme_options[intro_content]" class="large-text" cols="50" rows="10" name="client_theme_options[intro_content]"><?php echo esc_textarea( $options['intro_content'] ); ?></textarea>
<label class="description" for="client_theme_options[intro_content]"><?php _e( 'Enter content here to be displayed above the <em><strong>Posts</strong></em>.', 'client' ); ?></label>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'client' ); ?>" />
</p>
</form>
</div>
<?php
}
/**
* Sanitize and validate input. Accepts an array, return a sanitized array.
*/
function theme_options_validate( $input ) {
global $select_options, $radio_options;
// Our checkbox value is either 0 or 1
if ( ! isset( $input['option1'] ) )
$input['option1'] = null;
$input['option1'] = ( $input['option1'] == 1 ? 1 : 0 );
// Say our text option must be safe text with no HTML tags
$input['sometext'] = wp_filter_nohtml_kses( $input['sometext'] );
// Our select option must actually be in our array of select options
if ( ! array_key_exists( $input['selectinput'], $select_options ) )
$input['selectinput'] = null;
// Our radio option must actually be in our array of radio options
if ( ! isset( $input['radioinput'] ) )
$input['radioinput'] = null;
if ( ! array_key_exists( $input['radioinput'], $radio_options ) )
$input['radioinput'] = null;
// Say our textarea option must be safe text with the allowed tags for posts
$input['sometextarea'] = wp_filter_post_kses( $input['sometextarea'] );
return $input;
}
// adapted from http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/
register_setting()
call and sanitization callback function?