Created
April 23, 2011 18:18
-
-
Save franz-josef-kaiser/938844 to your computer and use it in GitHub Desktop.
Example plugin for how to add a button to tinymce in wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() | |
{ | |
tinymce.create('tinymce.plugins.BrettsYouTube', | |
{ | |
init : function(ed, url) { | |
ed.addButton('brettsyoutube', | |
{ | |
title : 'brettsyoutube.youtube', | |
image : 'http://localhost/wordpress/wp-includes/js/tinymce/themes/advanced/img/icons.gif', | |
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 : "Brett's YouTube Shortcode", | |
author : 'Brett Terpstra', | |
authorurl : 'http://brettterpstra.com/', | |
infourl : 'http://brettterpstra.com/', | |
version : "1.0" | |
}; | |
} | |
}); | |
tinymce.PluginManager.add( 'brettsyoutube', tinymce.plugins.BrettsYouTube ); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy into a folder named "tinymce-add-button" inside your wordpress plugins directory.