最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Why does plugin_url append absolute file path?

programmeradmin1浏览0评论

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
  • you don't use the function conveniently, read the documentation : codex.wordpress/Function_Reference/plugins_url – Kaperto Commented Dec 19, 2019 at 22:41
  • Can you share with us how you are registering the my-payflow-plugin script? I can only see the enquing – Tom J Nowell Commented Dec 19, 2019 at 23:02
  • 1 thanks, how are you testing the value of pluginUrl? 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
  • 1
发布评论

评论列表(0)

  1. 暂无评论