I try to make a plugin for wordpress, where I need a button in the TinyMCE editor. I have tried several tutorials, and I can get the button in the toolbar, but it will not open a window. I have tried to follow this example: http://return-true.com/2011/12/adding-tinymce-button-to-wordpress-via-a-plugin/
My javascript code:
// JavaScript Document
(function() {
tinymce.create("tinymce.plugins.afflpad", {
init : function(ed, url) {
ed.addCommand("afflpad_click", function() {
ed.windowManager.open({
file : url.substring(0, url.length -2) + "afflpad_selector.php",
width : 480,
height : auto,
inline: 1,
}, {
plugin_url : url
});
});
ed.addButton("afflpad_button", {
title : "Affiliate Link",
cmd : "afflpad_click",
image : url.substring(0, url.length -2) + 'img/afflpad_button.png'
});
},
getInfo : function() {
return {
longname : "Affiliate links",
author : "NAME",
authorurl : "HOMEPAGE",
infourl : "HOMEPAGE",
version : tinymce.majorVersion + "." + tinymce.minorVersion
};
}
});
tinymce.PluginManager.add("afflpad", tinymce.plugins.afflpad);
})();
And my PHP code for implementing in wordpress:
function afflpad_mce_buttonhooks() {
if(current_user_can("edit_posts") && current_user_can("edit_pages") && get_user_option("rich_editing") == "true") {
add_filter("mce_external_plugins", "afflpad_register_tinymce_javascript");
add_filter("mce_buttons", "afflpad_register_mce_buttons");
}
}
add_action("init", "afflpad_mce_buttonhooks");
function afflpad_register_tinymce_javascript($plugin_array) {
$plugin_array["afflpad"] = plugins_url("/js/afflpad_tinymce_plugin.js", __file__);
return $plugin_array;
}
function afflpad_register_mce_buttons($buttons) {
array_push($buttons, "|", "afflpad_button");
return $buttons;
}
Can someone see why I can't open a window, when clicking on the button?