3

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
1

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');}}
            ]
        });
    }
    });

0
1

Unfortunately I had the same problem and I had to rewrite my plugin. See this TinyMCE Fiddle

I've created an example to add a button to insert a shortcode (insert or wrap selection).

tinymce.PluginManager.add('example', function(editor, url) {
// Add a button that insert a shortcode
editor.addButton('example', {
    text: 'Custom Button',
    icon: false,
    onclick: function() {
        // Do something...
        if (editor.selection.getContent())
        {
            editor.selection.setContent('[aff afftitle="" afflink=""]' + editor.selection.getContent() + '[/aff]');
        }
        else
        {
            editor.selection.setContent('[aff afftitle="" afflink=""]Your text here...[/aff]');
        }
    }
});

});

Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.