0

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

2
  • I think that __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 at 11:54
  • I use constant in main plugin (defined in other plugin) to check if other plugin is activated. Strange that plugin_dir_url cannot return plugins directory on its own.
    – Toniq
    Commented Aug 21 at 14:39

1 Answer 1

0

It 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.