我找到了一个代码集,可以将YouTube按钮添加到WP tinyMCE编辑器中,我现在正试图将其合并到主题子主题中。然而,当我将代码添加到子主题函数文件并包含js时,它不仅没有添加YouTube按钮,实际上还使整个TinyMCE厨房水槽消失。真倒霉
在函数调用中是否有一些我遗漏的特定于主题的变化,这可能会使此添加工作正常?没有它,项目不会失败,但肯定会得到加强。请参见下面的代码:
功能代码
<?php
// Add these functions to your functions.php file
// add the shortcode handler for YouTube videos
function addYouTube($atts, $content = null) {
extract(shortcode_atts(array( "id" => \'\' ), $atts));
return \'<p style="text-align:center"><a href="http://www.youtube.com/v/\'.$id.\'"><img src="http://img.youtube.com/vi/\'.$id.\'/0.jpg" width="400" height="300" /><span>Watch the video</span></a></p>\';
}
add_shortcode(\'youtube\', \'addYouTube\');
function add_youtube_button() {
// Don\'t bother doing this stuff if the current user lacks permissions
if ( ! current_user_can(\'edit_posts\') && ! current_user_can(\'edit_pages\') )
return;
// Add only in Rich Editor mode
if ( get_user_option(\'rich_editing\') == \'true\') {
add_filter("mce_external_plugins", "add_youtube_tinymce_plugin");
add_filter(\'mce_buttons\', \'register_youtube_button\');
}
}
function register_youtube_button($buttons) {
array_push($buttons, "|", "youryoutube");
return $buttons;
}
// Load the TinyMCE plugin : editor_plugin.js (wp2.5)
function add_youtube_tinymce_plugin($plugin_array) {
$plugin_array[\'youryoutube\'] = get_bloginfo(\'template_url\').\'/editor_plugin.js\';
return $plugin_array;
}
function my_refresh_mce($ver) {
$ver += 3;
return $ver;
}
// init process for button control
add_filter( \'tiny_mce_version\', \'my_refresh_mce\');
add_action(\'init\', \'add_youtube_button\');
?>
javascript
(function() {
tinymce.create(\'tinymce.plugins.YourYouTube\', {
init : function(ed, url) {
ed.addButton(\'youryoutube\', {
title : \'youryoutube.youtube\',
image : url+\'/youtube.png\',
onclick : function() {
idPattern = /(?:(?:[^v]+)+v.)?([^&=]{11})(?=&|$)/;
var vidId = prompt("YouTube Video", "Enter the id or url for your video");
var m = idPattern.exec(vidId);
if (m != null && m != \'undefined\')
ed.execCommand(\'mceInsertContent\', false, \'[youtube id="\'+m[1]+\'"]\');
}
});
},
createControl : function(n, cm) {
return null;
},
getInfo : function() {
return {
longname : "YouTube Shortcode",
author : \'Brett Terpstra\',
authorurl : \'http://brettterpstra.com/\',
infourl : \'http://brettterpstra.com/\',
version : "1.0"
};
}
});
tinymce.PluginManager.add(\'youryoutube\', tinymce.plugins.YourYouTube);
})();
任何帮助都将不胜感激。