701 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
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
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 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
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
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