wp_editor textarea value not updating

I am using the *_add_form_fields action to add fields to a custom taxonomy. One of those fields is a wp_editor().

The problem I am facing is that when I output the WordPress editor on the page like so:

wp_editor('test', 'mydescription', array('textarea_name' => 'my_description')); 

and then if I click in the editor on the page and change the default value from test to something else the $_POST['my_description'] variable is still set to test

Should I be adding an additional setting to my editor? Is there a reason why I cannot change the value of the textarea?

EDIT

Below is a very simple test case that shows this happening. Place this in your functions.php file and then create a new tag. The posted value for ‘my_description” will not change.

class Test{

    function __construct() {

        add_action('add_tag_form_fields', array($this, 'add_tag_form_fields'));

        add_action('created_term', array($this, 'created_term'));
    }

    function add_tag_form_fields($tag){

        if ( current_user_can( 'publish_posts' ) ): ?>

        <div class="form-field">
            <?php wp_editor('test', 'mydescription', array('textarea_name' => 'my_description')); ?>
        </div>

        <?php
    }

    function created_term($tag){
        echo '<pre>';
        print_r($_POST);
        echo '</pre>';
            die();
    }
}
new Test();

EDIT

This ONLY happens when attaching to “created_term” action. If you attach to “edited_terms” it works as expected and I think this is a result of ajax being used on the create term page… I have updated the test code to show this.

3

tinyMCE <textarea> element is initially unseen by the used serialize function:

$.post(
    ajaxurl,
    $('#addtag').serialize(), function(r) {
        // Content here.
    }
});

You will need to call tinyMCE.triggerSave() to make it visible.

Below is a simple snippet that should do the trick:

jQuery('#submit').mousedown( function() {
    tinyMCE.triggerSave();
});

This in an external file, enqueued with wp_enqueue_script(); it worked for the test I’ve conducted.

Leave a Comment