701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
chrismccoy says

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() {
3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

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 = '&lt;?php echo YOUR_PLUGIN_DIR; ?&gt;';
</script>
&gt;?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

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

Obviously the php tags get screwed here, I really can’t find a way to post them in a readable way… :(

701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
chrismccoy says

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() {
by
by
by
by
by
by