我在wordpress自定义插件中使用自定义MCE按钮下面是我的代码
function enqueue_plugin_scripts($plugin_array)
{
//enqueue TinyMCE plugin script with its ID.
$plugin_array["related_post_button"] = plugin_dir_url(__FILE__) . "index.js";
return $plugin_array;
}
add_filter("mce_external_plugins", "enqueue_plugin_scripts");
和js索引。js是
(function() {
tinymce.create("tinymce.plugins.related_post_button", {
//url argument holds the absolute url of our plugin directory
init : function(ed, url) {
//add new button
ed.addButton("related_btn", {
title : "Add Related post shortcode",
cmd : "related_command",
icon: "custom-mce-icon",
});
//button functionality.
ed.addCommand("related_command", function() {
var selected_text = ed.selection.getContent();
var return_text = selected_text + "[related]";
ed.execCommand("mceInsertContent", 0, return_text);
});
},
createControl : function(n, cm) {
return null;
},
getInfo : function() {
return {
longname : "Extra Buttons",
author : "Narayan Prusty",
version : "1"
};
}
});
tinymce.PluginManager.add("related_post_button", tinymce.plugins.related_post_button);
})();
要翻译任何内容,我在php中使用此代码
_e( "text to tranlate", \'wp-related-articles-acf\' );
但是,当我有了代码时,如何实现这一点呢
index.js
title : "Add Related post shortcode",
请注意,所有内容都得到了正确的翻译,我只是想知道如何才能做到这一点
我已经试过了https://codex.wordpress.org/Plugin_API/Filter_Reference/mce_external_languages 但不起作用
SO网友:Ravi Patel
创建js文件按钮。js和添加js目录并列出btn。需要png
(function() {
tinymce.create("tinymce.plugins.listbuttons_button_plugin", {
//url argument holds the absolute url of our plugin directory
init : function(ed, url) {
//add new button
ed.addButton("listbuttons", {
title : "Add Related post shortcode",
cmd : "listbuttons_command",
image : "images/list-btn.png"
});
ed.addCommand("listbuttons_command", function() {
var return_text = "[related]";
ed.execCommand("mceInsertContent", 0, return_text);
});
},
createControl : function(n, cm) {
return null;
},
getInfo : function() {}
});
tinymce.PluginManager.add("listbuttons_button_plugin", tinymce.plugins.listbuttons_button_plugin);
})();
在函数中添加代码。php
function enqueue_plugin_scripts($plugin_array){
$plugin_array["listbuttons_button_plugin"] = get_template_directory_uri() . "/js/buttons.js";
return $plugin_array;
}
add_filter("mce_external_plugins", "enqueue_plugin_scripts");
function register_buttons_editor($buttons){
array_push($buttons, "listbuttons");
return $buttons;
}
add_filter("mce_buttons", "register_buttons_editor");
function shortcode_button_script(){
if(wp_script_is("quicktags")){
?>
<script type="text/javascript">
QTags.addButton("list_buttons_shortcode","Add Related post shortcode",callback);
function callback(){
QTags.insertContent("[listbuttons]");
}
</script>
<?php
}
}
add_action("admin_print_footer_scripts", "shortcode_button_script");