I’m creating a short-code generator for the WordPress Add/Edit Post/Page screen.
I want to make sure that there does not exist more than one short-code in the same post/page. So I added an onclick
function for the button so that whether there already exist a short-code, could be checked.
How do I go on doing this?
I searched around the TinyMCE API and the closest I got was the tinymce.Formatter.match method. But there’s no example on this page. I don’t really think that this has anything to do with the content search anyway.
Another way would be to simply use the getContent method and run javascript code against it. But I guess this wouldn’t be the best option if there’s something built-in for this already.
I do not know exactly what you mean by the term “short-code”.
But i guess it is a string you can find using getContent-Method.
There are several other ways to search the editor content.
Since tinymce editor is rendered inside an iframe and is indeed real html code you can use all regular DOM-Methods of your browser. There are even some additional DOM-Methods provided in
tiny_mce/classes/dom/DOMUtils.js
.