Help: Loading wp_editor in ajax


#1

Hello Guys,

I need your help i am trying to load the wp_editor in an ajax instance in the backend, but it seems like not showing any of the buttons and visual/html is now working … nothing works.

Any thought how it can be fixed ?


#2

Good luck with that, it’s hell :slight_smile: I would suggest rethinking the concept and avoiding that if anyhow possible.


#3

Well … i am afraid i don’t have another choice … that’s the way i built my page builder :smiley:


#4

Check this discussion on how we do it: http://themeforest.net/forums/thread/who-has-got-an-awesome-wordpress-drag-and-drop-page-builder-in-their-theme-/107638?page=6#message_content_966919


#5

I am sorry i don’t see a straight solution, you are talking about tinymce vs ckeditor and i want to reinitiate the tinymce after the ajax call.


#6

No, we discuss on how we implemented TinyMCE into our own page editor. SO basically, idea is to instantiate one instance of wp_editor in the background, and then you dynamically call that editor into view based on your needs.


#7
OriginalEXE said

then you dynamically call that editor into view based on your needs.

thanks the point, i have been looking in the past week on how to do it and i didn’t manage to find it :frowning:


#8

It’s simple.

Output it on a hidden div, then just apply display: block on it when needed and hide the rest, and do reverse once you’re finished editing.


#9

I’d like to post my solution since this thread is one of the first results on google and could be useful to many.

The point is that WP compiles a configuration object for each editor and it could be used only once in a webpage. The trick is to store the config object, manipulate it to manage your ajax editor and trigger tinymce.init()

Code for the webpage

<?php 
// create hidden fake editor
echo '
'; wp_editor('', 'editor_id'); echo '
'; ?>

Code for ajax response

<?php
$eid =  'NEW_editor_id';
wp_editor('', $eid);
?>


Simple, isn’t it? But has been a real nightmare to figure everything out without using absurd resources :smiley:


#10

LCweb’s solution works like a charm. Sorry to bump an old thread but I had say “thanks” - your post has saved an otherwise very frustrating evening!