admin管理员组文章数量:1122846
I hvae a plugin which includes php file from another plugin.
So I would do this:
plugin 'foo' includes file from plugin 'blah':
wp-content/plugins/foo
include(__DIR__."/../blah/some-file.php");
This works but I am sure if I like this ../ , I wanted to reference plugin directory like:
include( WP_PLUGIN_DIR.'/blah/some-file.php' );
This works as well, but it say here:
WordPress makes use of the following constants when determining the path to the content and plugin directories. These should not be used directly by plugins or themes, but are listed here for completeness.
I cannot use plugin_dir_url() without an argument, like:
include( plugin_dir_url().'/blah/some-file.php' );
I can only do this:
include( plugin_dir_url(__FILE__).'/../blah/some-file.php' );
which is the same as first include above with DIR
I hvae a plugin which includes php file from another plugin.
So I would do this:
plugin 'foo' includes file from plugin 'blah':
wp-content/plugins/foo
include(__DIR__."/../blah/some-file.php");
This works but I am sure if I like this ../ , I wanted to reference plugin directory like:
include( WP_PLUGIN_DIR.'/blah/some-file.php' );
This works as well, but it say here:
WordPress makes use of the following constants when determining the path to the content and plugin directories. These should not be used directly by plugins or themes, but are listed here for completeness.
https://codex.wordpress.org/Determining_Plugin_and_Content_Directories
I cannot use plugin_dir_url() without an argument, like:
include( plugin_dir_url().'/blah/some-file.php' );
I can only do this:
include( plugin_dir_url(__FILE__).'/../blah/some-file.php' );
which is the same as first include above with DIR
Share Improve this question asked Aug 21, 2024 at 7:49 ToniqToniq 4476 silver badges15 bronze badges 2 |1 Answer
Reset to default 0It doesn't make a lot of sense, to me, to say "these should not be used directly by plugins". I tend to think you should use an available function over the constant - if an available function exists - which, in your case, does not. I would go ahead and use the WP_PLUGIN_DIR constant.
本文标签: plugin developmentUsing WPPLUGINDIR for include file
版权声明:本文标题:plugin development - Using WP_PLUGIN_DIR for include file 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296214a1929737.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
__DIR__
can be used in this case. but do you really need that ? you will have an error if you deactivate the plugin with the included file. I recommend to use communication between plugins like that : wordpress.stackexchange.com/questions/426353/… – mmm Commented Aug 21, 2024 at 11:54