(This is sort of a follow-up to this question.)
I’m able to display the two WYSIWYG editors on my theme options page, but the values I enter into the editors aren’t saved. I’ve read a ton of stuff about the Settings API and wp_editor() in hopes of making this work in the most WordPress-friendly way. I feel like I have yet to find a good explanation for how to make wp_editor()
work in theme settings while still saving properly according to the Settings API.
I’m getting the feeling that, despite the wp_editor()
calls being in the relevant settings field callbacks, the Save process isn’t realizing that the editors are associated with valid options.
The relevant code from my theme options is below:
//register settings
add_action( 'admin_init', 'us_register_settings' );
function us_register_settings() {
add_settings_section( 'us_settings', 'Settings', 'us_settings_section_cb', 'us_options' );
register_setting( 'us_settings', 'us_authors_desc', 'us_sanitize_wysiwyg' );
register_setting( 'us_settings', 'us_partners_desc', 'us_sanitize_wysiwyg' );
add_settings_field( 'us_authors_desc', 'Author Archives Descriptions', 'us_authors_cb', 'us_options', 'us_settings' );
add_settings_field( 'us_partners_desc', 'Partners Archives Descriptions', 'us_partners_cb', 'us_options', 'us_settings' );
}
function us_settings_section_cb() {
// no need for text here right now
}
function us_authors_cb() {
$us_author_desc = get_option( 'us_authors_desc' );
echo wp_editor( $us_author_desc, 'usauthorsdesc' );
}
function us_partners_cb() {
$us_partners_desc = get_option( 'us_partners_desc' );
echo wp_editor( $us_partners_desc, 'uspartnersdesc' );
}
function us_sanitize_wysiwyg( $input ) {
return $input;
}
function us_options_page() {
?>
<div class="wrap">
<h2>Options</h2>
<form method="post" action="options.php">
<?php
settings_fields( 'us_settings' );
do_settings_sections( 'us_options' );
?>
<input name="Submit" class="button-primary" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</form>
</div>
<?php
}
EDIT: Right now, I’m also not using a call back on my settings. Is that possibly the issue?
UPDATE: Added callback function in code. No difference.
You need to add a name attribute to your editors. The name attribute needs to be set to the value of of your option, so like this: