qTranslate-Team/qtranslate-x

js script integration: absolute file path doesn't work

picasso opened this issue · 5 comments

When I need JS script to be executed before or after the line “new qTranslateX” - there is an option to add my script with JSON-encoded configuration.

The description from your docs:

‘src’ – file path, which is relative to ‘wp-content’ directory. If it starts with ‘./’, then the path is relative to > ‘plugins/qtranslate-x’ directory. Absolute file paths also acceptable.

the problem is that you always add 'plugins path' to the path from configuration field:

    $plugins_dir = WP_CONTENT_DIR.'/plugins/';
    foreach($page_config['js-conf'] as $js){
        if(!isset($js['src'])) continue;
        readfile($plugins_dir.$js['src']);
    }

I develop a theme, not a plugin. In my case it's very inconvenient to create a special path to my script relative to Plugins directory. Could you fix it?

Please, try using the latest from GitHub, that place already undergone a lot of changes. Let me know if it is still not good enough.

Ok, I've tried the latest from GitHub.
Anyway it does not work with the absolute path. You try to recognize if it the path is relative to Plugins or WP_Content... but my path is not relative - it's absolute. I just get it by get_stylesheet_directory() (as recommended for child theme).

I suggest to add to your code the following line (file qtx_admin.php between line #300 and #301):

if(file_exists($src)) continue;  // absolute path provided

That place not always read file from the system but sometimes enqueues it using content_url($src);. That is why $src is expected to be relative to WP_CONTENT_DIR. how do you suggest to change it so that we can still enqueue it as a URL?

There is a piece of code after line "//make src to be relative to WP_CONTENT_DIR", which converts the path provided into a path relative to WP_CONTENT_DIR. I modified it to take into account absolute paths. Please, test it and let me know if it is ok.

Thanks a lot.

Tested. Now it works.
Thanks a lot for wonderful support!

Good, I am glad. Yes, please, test the latest version as much as you can and let me know if you found something. I guess we can close this issue for now.