Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

(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.

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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:

function us_partners_cb() {
    $us_partners_desc = get_option( 'us_partners_desc' );
    echo wp_editor( $us_partners_desc, 'uspartnersdesc', array('textarea_name' => 'us_partners_desc')  );
}
share|improve this answer
    
Worked like a charm! Thanks. –  mrwweb May 6 '12 at 17:50
    
Great, glad to help. –  Pippin May 6 '12 at 17:57
    
thanks you Pippin.. always the best. –  Ronny Dec 19 '12 at 17:49
    
Thanks Pippin! I've spent hours trying to figure this out. Can't believe that's all it took... –  Jeremiah Prummer Mar 31 at 4:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.