我实际上正在开发一个小的短代码插件。
在插件主文件上,我注册TinyMCE按钮并链接core js about按钮:
add_filter("mce_external_plugins", "shortcodes_tinymce_plugin");
add_filter("mce_buttons", "register_shortcodes_button");
function register_shortcodes_button($buttons) {
array_push($buttons, "separator", "shortcodes");
return $buttons;
}
function shortcodes_tinymce_plugin($plugin_array) {
$plugin_array[\'shortcodes\'] = PLUGINDIR_URI . \'tiny_mce_script.js\';
return $plugin_array;
}
其中包含以下代码:
(function() {
tinymce.create(\'tinymce.plugins.shortcodes\', {
init : function(ed, url) {
ed.addButton(\'shortcodes\', {
title : \'Utilizer shortcodes\',
image : url.replace(\'/js\',\'\')+\'/img/shortcodes.png\',
cmd : \'shortcodes\',
pluginurl : ajaxurl
});
ed.addCommand(\'shortcodes\', function() {
ed.windowManager.open({
file : url.replace(\'/js\',\'\')+\'../../tinymce_shortcode.php\',
width : 510 + parseInt(ed.getLang(\'button.delta_width\', 0)),
height : 415 + parseInt(ed.getLang(\'button.delta_height\', 0)),
inline : 1
}, {
plugin_url : url
});
});
}
});
tinymce.PluginManager.add(\'shortcodes\', tinymce.plugins.shortcodes);
}
)();
单击按钮时,模式页面将加载此文件tinymce\\u短代码。PHP在文档顶部包含以下内容:
<?php
require_once("../../../../wp-load.php");
if ( !current_user_can(\'publish_posts\') ) exit();
wp_register_script( \'shortcodes\', PLUGINDIR_URI . "shortcodes.js", false, "1.0", true );
wp_register_script( \'tiny-mce-popup\', PLUGINDIR_URI . "tiny_mce_popup.js", false, "1.0", true );
wp_enqueue_script(
array(
\'iris\',
\'json2\',
\'jquery\',
\'jquery-ui-core\',
\'jquery-ui-sortable\',
\'jquery-ui-tabs\',
\'jquery-ui-slider\',
\'jquery-ui-datepicker\',
\'jquery-ui-autocomplete\',
\'tiny-mce-popup\',
\'shortcodes\',
\'media-upload\',
\'thickbox\',
)
); ?>
然后在身体关闭前的右下角,我执行以下代码:
<?php do_action(\'admin_print_scripts\'); ?>
<?php do_action(\'admin_print_footer_scripts\'); ?>
所有javascript库都会加载,如jquery、jquery ui、media upload、thickbox、jso2等。只有iris颜色选择器库不会加载。非常感谢您的帮助。