Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert content to Wordpress post editor

I'm making a Wordpress plugin for adding image maps in the posts. Currently I have implemented the image maps as a custom post types. However I'm having some trouble with adding them in posts.

I have made a new tab in the media insert/upload window called Image map. When you click an image map in the tab, this function is fired:

function insertImageMap() {
    tinyMCE.execInstanceCommand('mceInsertContent', false, 'content',
    'some text or html code'
    );
    window.parent.tb_remove();
}

However nothing is added to the tinyMCE editor. The function is fired, but the instance of tinyMCE editor is undefined even if I use tinyMCE.getInstanceById('content'). Is there a way to access the editor of a post editor page?

I have included tinyMCE script in my plugin and it doesn't show as undefined.

I found an older question asking the same, but the answer wasn't very helpful: Custom Wordpress Plugin - How do I insert content from popup on post editor?

like image 640
Spike Avatar asked Nov 20 '25 12:11

Spike


1 Answers

Solution found in comments:

function insertImageMap() {
    window.parent.send_to_editor('any text');
    window.parent.tb_remove();
}
like image 195
Spike Avatar answered Nov 23 '25 03:11

Spike