WordPress TinyMCE: Switch Views

In order to complete my WordPress Plugin I want to make tinyMCE to switch between a custom Tag (Some|data|here) and a corresponding Image Display in the WYSIWYG-View.

The event should be triggered on load, safe, autosave, switch view etc. Threre are 4 different events defined, but none of them works as expected.

Read More
  1. onBeforeSetContent
  2. onGetContent
  3. onPostProcess
  4. onLoadContent

.

ed.onPostProcess.add(function(ed, o) {
    if (o.set){
       o.content = t._htmlToWysiwyg(o.content, url);
    }
    if (o.get){
       o.content = t._wysiwygToHtml(o.content, t);
    }
});

Anyon know the right way?

Related posts

Leave a Reply

1 comment

  1. I do not know what you expect the 4 different events will do (?), but i can see some problems in your code.

    1. The object o does not contain fields get and set – so o.get and o.set will never be true! Thus your code will never be called.

    2. You are using the variable url, but this one is not defined here.

    Working example: You may try to paste a string containing “a” into the editor. Use the following:

    ed.onPostProcess.add(function(ed, o) {
        //console.log('o:', o);
        o.content = o.content.replace(/a/g, "A");
    });
    

    You should see that all lower ‘a‘s get replaced by ‘A‘s.