I`m trying to insert custom button to my wordpress tinyMCE editor to call php function. I already inserted that button but i don’t know how to call php function. The JavaScript code is here:
Javascript:
(function() {
tinymce.create('tinymce.plugins.PreButton', {
init : function(ed, url) {
ed.addCommand('preFormat', function() {
ed.formatter.toggle('pre');
});
ed.addButton('pre', {
title : 'IMG',
text : 'IMG',
onclick : function() {
ed.windowManager.open({
title: 'Example plugin',
body: [
{type: 'textbox', name: 'img_url', label: 'IMG URL'},
{type: 'textbox', name: 'img_info', label: 'Info'}
],
onsubmit: function(e) {
// Insert content when the window form is submitted
ed.insertContent('<img src="' + e.data.img_url + '" alt="' + e.data.img_info + ' />');
}
});
}
});
},
});
// Register plugin
tinymce.PluginManager.add('preButton', tinymce.plugins.PreButton);
})();
PHP:
<?php
/**
* @package autoimage
* @version 1.0
*/
/*
Plugin Name: autoimage
*/
function mcepre_add_buttons($plugin_array) {
$plugin_array['preButton'] = plugins_url('mce-pre',__FILE__) . '/plugin.js';
return $plugin_array;
}
function mcepre_register_buttons($buttons) {
array_push( $buttons, 'pre');
return $buttons;
}
function mcepre_buttons() {
add_filter("mce_external_plugins", "mcepre_add_buttons");
add_filter('mce_buttons', 'mcepre_register_buttons');
}
add_action( 'init', 'mcepre_buttons' );