Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js script integration: absolute file path doesn't work #186

Closed
picasso opened this issue Jun 24, 2015 · 5 comments
Closed

js script integration: absolute file path doesn't work #186

picasso opened this issue Jun 24, 2015 · 5 comments

Comments

@picasso
Copy link

picasso commented Jun 24, 2015

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?

@johnclause
Copy link
Member

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.

@picasso
Copy link
Author

picasso commented Jun 25, 2015

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

@johnclause
Copy link
Member

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.

@picasso
Copy link
Author

picasso commented Jun 26, 2015

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

@johnclause
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants