I'm creating a WordPress plugin. It has a functionality to show the editor when adding a product through AJAX but the the editor is not showing properly.
User can add as many products as he want so keep in mind that there will be more than one wp_editor()
Please refer to the attached screenshot:
I have used the following code:
PHP
public function add_product() {
// Get product id
$prod_id = filter_input(INPUT_POST, 'pid');
// WordPress WYSIWYG Editor
wp_editor("Test Content", "textarea" . $prod_id, array('textarea_name' => 'text'));
wp_die();
}
JQUERY
$('.add-prod').live('click', function () {
var prod_id = $('.prod-id').val();
var data = {
action: 'add_prod',
pid: prod_id
};
$('#update-msg').show();
$.post(ajaxurl, data, function (result) {
$('#the-list').append(result);
$('#update-msg').hide();
});
return false;
});
I have used a solution from the internet but its partially working not fully. Used the following code:
PHP
wp_editor($product->prod_desc, $textarea_id, array('textarea_name' => 'text'));
\_WP_Editors::enqueue_scripts();
print_footer_scripts();
\_WP_Editors::editor_js();
JQUERY
var eid = '#item-list';
switchEditors.go(eid, 'tmce')
quicktags({id: eid});
//init tinymce
tinyMCEPreInit.mceInit[eid]['elements'] = eid;
tinyMCEPreInit.mceInit[eid]['body_class'] = eid;
tinyMCEPreInit.mceInit[eid]['succesful'] = false;
tinymce.init(tinyMCEPreInit.mceInit[eid]);
And the code above does this: