whats the best way to hardcore the image url for the button without doing it via the full path.
reason i ask, is sometimes people rename the plugin directory to something other than the extract is, and it will be a 404 image.
var button = controlManager.createButton('dlprotect_button', {
title : 'Download Protect', // title of the button
image : '../wp-content/plugins/download-protect-fork/images/download_protect.png', // path to the button's image
onclick : function() {
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
Mmm,
you should define some constants in your plugin, something like this:
if ( ! defined( 'YOUR_PLUGIN_BASENAME' ) )
define( 'YOUR_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
if ( ! defined( 'YOUR_PLUGIN_NAME' ) )
define( 'YOUR_PLUGIN_NAME', trim( dirname( YOUR_PLUGIN_BASENAME ), '/' ) );
if ( ! defined( 'YOUR_PLUGIN_DIR' ) )
define( 'YOUR_PLUGIN_DIR', '../wp-content/plugins/' . YOUR_PLUGIN_NAME );
and define a plugin function (in the right way) that prints the js var of the path in the admin head:
function your_plugin_head() {
if ( defined( 'YOUR_PLUGIN_DIR' ) ) :
?<
<script type="text/javascript">
var your_plugin_path = '<?php echo YOUR_PLUGIN_DIR; ?>';
</script>
>?php
endif;
}
add_action('admin_head', 'your_plugin_head');
Then you should be able to get the path (whatever the folder name of the plugin is) in your js script:
alert(your_plugin_path);
I didn’t test it, but should work.
Parker
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
Obviously the php tags get screwed here, I really can’t find a way to post them in a readable way… 
i ended up redoing the tinymce call instead of using createbutton i used addbutton and passed the url param via the init stage.
function(){
tinymce.create('tinymce.plugins.dlprotect_button', {
init : function(ed, url) {
ed.addButton('dlprotect_button', {
title : 'Download Protect',
image : url + '/../images/download_protect.png',
onclick : function() {
