0

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 :

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

2 Answers 2

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
  • 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
    Commented Sep 23, 2014 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.

5
  • 2
    Please explain why this answer is helpful.
    – kaiser
    Commented Sep 10, 2014 at 12:39
  • It helped me. I used thickbox to open the popup with editor. Commented Sep 11, 2014 at 13:12
  • Ok, it helped you. Now please explain why it helped.
    – kaiser
    Commented Sep 11, 2014 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. Commented Sep 12, 2014 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
    Commented Sep 12, 2014 at 16:35

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