Wordpress - wp_editor textarea value not updating
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.
In your edited_terms
function you need to save the value and in your add_tag_form_fields
you need replace your test
with the saved data.
something like:
class Test{
function __construct() {
//do_action('add_tag_form_fields', $taxonomy);
add_action('add_tag_form_fields', array($this, 'add_tag_form_fields'));
//do_action("edited_terms", $term_id, $tt_id, $taxonomy);
add_action('edited_terms', array($this, 'edited_terms'));
}
function add_tag_form_fields($term){
if ( current_user_can( 'publish_posts' ) ): ?>
<div class="form-field">
<?php
$saved = get_option('termmeta_'.$term->term_id);
$saved = (empty($saved))? 'test': $saved;
wp_editor($saved, 'mydescription', array('textarea_name' => 'my_description')); ?>
</div>
<?php
}
function edited_terms($term_id){
if (isset($_POST['mydescription'])){
update_option('termmeta_'.$term_id,$_POST['mydescription']);
}
}
}
new Test();
Now if you want a much easier way of adding extra fields of all types to your tags/categories or custom taxonomy edit forms without reinventing the wheel take a look at TAX Meta Class