0

This question already has an answer here:

I try to use wp_editor() in content that was loaded with ajax, but none of the required files and some other configuration script not loaded :

The structure of ajax is something like this:

function get_test_page(){
   include( TEMPLATEPATH . '/page.php' );
   die( main() );
}
add_action( 'wp_ajax_nopriv_get_test_page', 'get_test_page' );
add_action( 'wp_ajax_get_test_page', 'get_test_page' );

page.php :

function main(){
    wp_editor('','unique_id');
}

Editor is loaded but needed files is not loaded.

  • http://.../wp-includes/js/tinymce/wp-tinymce.php

  • http://.../wp-includes/js/tinymce/skins/lightgray/skin.min.css

  • http://.../wp-admin/load-scripts.php?c=1&load%5B%5D=...mce-view,imgareaselect,image-edit,word-count,editor,quicktags,wplink,thick...

  • http://.../wp-includes/js/tinymce/langs/{}.js

Some related post but doesn't help me :

marked as duplicate by kaiser Sep 23 '14 at 0:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please elaborate on what you are doing. "loaded with ajax" is not much detail. – Rarst Jun 20 '14 at 19:43
  • @Rarst I added more detail. – myvahid Jun 20 '14 at 20:38
  • get_page() is a built-in WordPress function. You cannot redeclare a function. Fix this error, then try again. – fuxia Jun 20 '14 at 21:13
  • @toscho this is an example, I changed it. – myvahid Jun 21 '14 at 4:46
0

Solution:

Add wp_editor() in somewhere that works perfectly and hide it.

<div class="hidden-editor-container" style="display:none;">
    <?php wp_editor( '', 'editor' ); ?>
</div>

after that assign editor contents to the global JS variable.

EDITOR = $('.hidden-editor-container').contents();

Finally when the ajax page is loaded append editor contents

$('.editor').append( EDITOR );

tinymce.execCommand( 'mceRemoveEditor', false, 'editor' );
tinymce.execCommand( 'mceAddEditor', false, 'editor' );
  • 1
    I'd recommend against your solution. Aside from the missing var declaration, there are better solutions. Please see the answers in the "duplicate" linked question. – kaiser Sep 23 '14 at 0:15
-1

Try add

do_action('admin_print_footer_scripts');

after

wp_editor('','unique_id');

Action 'admin_print_footer_scripts' load needed files for editor. In popup this action not work, because in admin panel is_admin() is false (see wp-includes/class-wp-editor.php function editor_settings). May be a bug.

  • 2
    Please explain why this answer is helpful. – kaiser Sep 10 '14 at 12:39
  • It helped me. I used thickbox to open the popup with editor. – Александр Виткалов Sep 11 '14 at 13:12
  • Ok, it helped you. Now please explain why it helped. – kaiser Sep 11 '14 at 13:18
  • Action 'admin_print_footer_scripts' load needed files for editor. In popup this action not work, because in admin panel is_admin() is false (see wp-includes/class-wp-editor.php function editor_settings). May be a bug. – Александр Виткалов Sep 12 '14 at 14:24
  • That's an explanation. Could you please add it as an edit? Then I can remove the downvote and not delete it. Thanks. – kaiser Sep 12 '14 at 16:35

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