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?
tinyMCE
instance, you need to get it through eitherwindow.opener
orwindow.parent
(I'm not 100% sure if it's any of those or something else). So you can dovar instance = window.opener.tinyMCE || window.parent.tinyMCE; instance.execInstanceCommand('mceInsertContent', false, 'content', 'some text or html code');
. In addition you can look through the source code(most-likely the JS) and see how WordPress sends the content to the editor. – Nikola Ivanov Nikolovwindow.send_to_editor()
? – Nikola Ivanov Nikolovwindow.send_to_editor('content to go to editor here')
and tell me if it works. – Nikola Ivanov Nikolov