$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - wp.editor.initialize does nothing|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - wp.editor.initialize does nothing

matteradmin8PV0评论

I'm trying to add additional wp_editor instances when a user clicks an "Add content" button in the back-end. I have it mostly working, except that the user needs to save the post after adding the field in order for the TinyMCE editor to appear, as it's initialized with the PHP wp_editor() function.

After some digging, I found the wp.editor.initialize() (docs) JavaScript function, which seems like it should initialize a new editor given a textarea's ID.

This doesn't seem to work, no matter what I try. I have the following code:

<textarea id="custom-tinymce-testing" name="custom-tinymce-testing"></textarea>

Which I try to initialize with JavaScript after clicking a button:

wp.editor.initialize("custom-tinymce-testing", {
    mediaButtons: true,
    tinymce: true,
    quicktags: true,
});

This doesn't appear to do anything; the textarea remains unchanged, and no console errors are thrown. Running console.log(wp.editor.initialize()) does show that the function exists, so I don't think it's an ordering thing.

What am I doing wrong here?

I'm trying to add additional wp_editor instances when a user clicks an "Add content" button in the back-end. I have it mostly working, except that the user needs to save the post after adding the field in order for the TinyMCE editor to appear, as it's initialized with the PHP wp_editor() function.

After some digging, I found the wp.editor.initialize() (docs) JavaScript function, which seems like it should initialize a new editor given a textarea's ID.

This doesn't seem to work, no matter what I try. I have the following code:

<textarea id="custom-tinymce-testing" name="custom-tinymce-testing"></textarea>

Which I try to initialize with JavaScript after clicking a button:

wp.editor.initialize("custom-tinymce-testing", {
    mediaButtons: true,
    tinymce: true,
    quicktags: true,
});

This doesn't appear to do anything; the textarea remains unchanged, and no console errors are thrown. Running console.log(wp.editor.initialize()) does show that the function exists, so I don't think it's an ordering thing.

What am I doing wrong here?

Share Improve this question asked Feb 18, 2019 at 18:16 JacobTheDevJacobTheDev 1,2535 gold badges18 silver badges38 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

This was way simpler than I thought it was – even on post.php, you need to run wp_enqueue_editor() before using wp.editor in JavaScript. I had assumed that I wouldn't need to do that, because an editor was already loaded.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far