I'm, passing the plugin url parameter to my .js file using:
wp_enqueue_script('nova-payflow-plugin');
wp_localize_script('my-payflow-plugin', 'pluginValues', array(
'pluginUrl' => plugins_url(__DIR__),
));
In my script, I retrieve what should be a url to my plugin folder, but it looks like this:
/wp-content/plugins/C:/xampp/htdocs/mywebfolder/wp-content/plugins/my-plugin
On the Linux production server it does a similar thing:
/wp-content/plugins/homepages/40/d107997204/htdocs/mywebfolder/wp-content/plugins/my-payflow
Note that in the plugins url, a fully qualified Windows path appears appended immediately after wp-content/plugins/
Why does plugins_url add the absolute file path, but more importantly, I don't want it appended to the url string.
Here is how I'm enqueuing the scripts, if it matters to the question:
add_action('wp_enqueue_scripts', 'npf_styles_and_scripts');
function npf_styles_and_scripts() {
wp_register_style('nova-payflow-plugin', plugins_url('css/npf.css',__FILE__ ));
wp_enqueue_style('nova-payflow-plugin');
wp_register_script( 'nova-payflow-plugin', plugins_url('js/npf.js',__FILE__ ));
wp_enqueue_script('nova-payflow-plugin');
wp_localize_script('nova-payflow-plugin', 'pluginValues', array(
'pluginUrl' => plugins_url(),
));
}
I'm, passing the plugin url parameter to my .js file using:
wp_enqueue_script('nova-payflow-plugin');
wp_localize_script('my-payflow-plugin', 'pluginValues', array(
'pluginUrl' => plugins_url(__DIR__),
));
In my script, I retrieve what should be a url to my plugin folder, but it looks like this:
http://mysubdomain.mydomain.local/wp-content/plugins/C:/xampp/htdocs/mywebfolder/wp-content/plugins/my-plugin
On the Linux production server it does a similar thing:
https://mysubdomain.mydomain.online/wp-content/plugins/homepages/40/d107997204/htdocs/mywebfolder/wp-content/plugins/my-payflow
Note that in the plugins url, a fully qualified Windows path appears appended immediately after wp-content/plugins/
Why does plugins_url add the absolute file path, but more importantly, I don't want it appended to the url string.
Here is how I'm enqueuing the scripts, if it matters to the question:
add_action('wp_enqueue_scripts', 'npf_styles_and_scripts');
function npf_styles_and_scripts() {
wp_register_style('nova-payflow-plugin', plugins_url('css/npf.css',__FILE__ ));
wp_enqueue_style('nova-payflow-plugin');
wp_register_script( 'nova-payflow-plugin', plugins_url('js/npf.js',__FILE__ ));
wp_enqueue_script('nova-payflow-plugin');
wp_localize_script('nova-payflow-plugin', 'pluginValues', array(
'pluginUrl' => plugins_url(),
));
}
Share
Improve this question
edited Dec 20, 2019 at 16:26
TARKUS
asked Dec 19, 2019 at 22:16
TARKUSTARKUS
13710 bronze badges
8
my-payflow-plugin
script? I can only see the enquing – Tom J Nowell ♦ Commented Dec 19, 2019 at 23:02pluginUrl
? I hope you're not making AJAX calls to a PHP file in that folder, major security issues if you are, amongst other reasons, there are far, far better ways to do AJAX in WP that are safer faster and easier. – Tom J Nowell ♦ Commented Dec 20, 2019 at 1:47