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
herrvigg opened this issue Jun 22, 2018 · 5 comments
Closed

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

herrvigg opened this issue Jun 22, 2018 · 5 comments
Labels
enhancement New feature or request legacy issue Legacy issue imported from original repo need info The submitter must provide more info

Comments

@herrvigg
Copy link
Collaborator

Issue by picasso
Wednesday Jun 24, 2015 at 10:19 GMT
Originally opened as qTranslate-Team/qtranslate-x#186


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?

@herrvigg herrvigg added enhancement New feature or request legacy issue Legacy issue imported from original repo need info The submitter must provide more info labels Jun 22, 2018
@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Wednesday Jun 24, 2015 at 15:38 GMT


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.

@herrvigg
Copy link
Collaborator Author

Comment by picasso
Thursday Jun 25, 2015 at 14:29 GMT


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

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Jun 25, 2015 at 17:16 GMT


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.

@herrvigg
Copy link
Collaborator Author

Comment by picasso
Friday Jun 26, 2015 at 09:42 GMT


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

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Friday Jun 26, 2015 at 15:02 GMT


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
Labels
enhancement New feature or request legacy issue Legacy issue imported from original repo need info The submitter must provide more info
Projects
None yet
Development

No branches or pull requests

1 participant