Custom Shortcode and Button not Working after 3.9 update

I have added a new button that creates a short code but it seems that after the newest WordPress update, the button is not working any more. The button is visible but when someone clicks it, nothing happens.

The code I used is the following- js part

(function() {
tinymce.create('tinymce.plugins.affiliate', {
    init : function(ed, url) {
        ed.addButton('affiliate', {
            title : 'Add Affiliate Link',
            cmd : 'Affiliate link',
            image : url+'/euro.png',
            onclick : function() {
                 ed.selection.setContent('[aff afftitle="" afflink=""]' + ed.selection.getContent() + '[/aff]');

            }
        });
    },
    createControl : function(n, cm) {
        return null;
    },
});
tinymce.PluginManager.add('affiliate', tinymce.plugins.affiliate);
})();

Ι also have written code for the PHP Part, but I am not sure if the problem is there.I thing that the problem is in the JavaScript above.

Ι know that createControl doesn’t exist any more. I am trying to get around this issue but with no luck at this time.

2 Answers
2

Try like this:

<script type="text/javascript">
    tinymce.init({
    selector: "textarea",
    toolbar: "mybutton",
    setup: function(editor) {
        editor.addButton('mybutton', {
            type: 'splitbutton',
            text: 'My button',
            icon: false,
            onclick: function() {
                editor.insertContent('Main button');
            },
            menu: [
                {text: 'Menu item 1', onclick: function() {
                                  tinyMCE.activeEditor.execCommand("myPopup", false, {
                                      title: 'Divider',
                                      identifier: 'divider'
                              })}},
                {text: 'Menu item 2', onclick: function() {editor.insertContent('Menu item 2');}}
            ]
        });
    }
    });

Leave a Comment