Wordpress 插件批准标准:## 调用文件位置不佳
Wordpress plugin approval standards: ## Calling file locations poorly
我已向 Wordpress.org 提交了一个小部件并收到了此指导:
The way your plugin is referencing other files is not going to work
with all setups of WordPress.
When you hardcode in paths like wp-content or your plugin folder name,
or assume that everyone has WordPress in the root of their domain, you
cause anyone using 'Giving WordPress it's own directory' (a VERY
common setup) to break. In addition, WordPress allows users to change
the name of wp-content, so you would break anyone who chooses to do
so.
Please review the following link and update your plugin accordingly.
And don't worry about supporting WordPress 2.x or lower. We don't
encourage it nor expect you to do so, so save yourself some time and
energy.
Remember to make use of the FILE variable, in order than your
plugin function properly in the real world.
Example(s) from your plugin:
my-widget/includes/my-widget-scripts.php:6:
wp_enqueue_style('my-widget-main-style', plugins_url(). '/my-widget/css/style.css');
my-widget/includes/my-widget-scripts.php:8:
wp_enqueue_script('my-widget-main-script', plugins_url(). '/my-widget/js/main.js');
我遵循了 link 并尝试了其中的一些变体,但没有任何方法可以替代我目前拥有的代码(在引用底部找到)。
我应该用什么替换它才符合Wordpress.org的标准?
以下是我在自己的系统中的做法:
wp_enqueue_script( 'my-widget-main-style', plugins_url('/js/main.js', __FILE__) );
查看 plugins_url()
. The first argument takes a $path
argument to a append to the URL. The second takes a full path to a plugin. if you pass the __FILE__
Magic Constant 的文档,它将适用于您当前的插件。
你应该利用 两个 的参数:
wp_enqueue_style( 'my-widget-main-style', plugins_url( '/css/style.css', __FILE__ );
wp_enqueue_script( 'my-widget-main-script', plugins_url( '/js/main.js', __FILE__ );
我已向 Wordpress.org 提交了一个小部件并收到了此指导:
The way your plugin is referencing other files is not going to work with all setups of WordPress.
When you hardcode in paths like wp-content or your plugin folder name, or assume that everyone has WordPress in the root of their domain, you cause anyone using 'Giving WordPress it's own directory' (a VERY common setup) to break. In addition, WordPress allows users to change the name of wp-content, so you would break anyone who chooses to do so.
Please review the following link and update your plugin accordingly. And don't worry about supporting WordPress 2.x or lower. We don't encourage it nor expect you to do so, so save yourself some time and energy.
Remember to make use of the FILE variable, in order than your plugin function properly in the real world.
Example(s) from your plugin:
my-widget/includes/my-widget-scripts.php:6:
wp_enqueue_style('my-widget-main-style', plugins_url(). '/my-widget/css/style.css');
my-widget/includes/my-widget-scripts.php:8:
wp_enqueue_script('my-widget-main-script', plugins_url(). '/my-widget/js/main.js');
我遵循了 link 并尝试了其中的一些变体,但没有任何方法可以替代我目前拥有的代码(在引用底部找到)。
我应该用什么替换它才符合Wordpress.org的标准?
以下是我在自己的系统中的做法:
wp_enqueue_script( 'my-widget-main-style', plugins_url('/js/main.js', __FILE__) );
查看 plugins_url()
. The first argument takes a $path
argument to a append to the URL. The second takes a full path to a plugin. if you pass the __FILE__
Magic Constant 的文档,它将适用于您当前的插件。
你应该利用 两个 的参数:
wp_enqueue_style( 'my-widget-main-style', plugins_url( '/css/style.css', __FILE__ );
wp_enqueue_script( 'my-widget-main-script', plugins_url( '/js/main.js', __FILE__ );