I’m creating a plugin I would like to use from other different plugins. This plugin declares classes and functions. So, I am thinking about the best way to include, from one plugin, a php file present in another plugin.
I think this should work:
require_once WP_PLUGIN_DIR . "/the-other-plugin/required-file.php";
But I am not sure; is it a good solution? I think this would work even if the-other-plugin
is not enabled, and probably that is not a good idea.
This can be done also by using Must Use Plugins. Is this a best practice, or is the other solution better?
In your plugin add a custom action to let other plugins start after your basic code has done the work:
Other plugins can start their work now like this:
They will never do anything if your base plugin is not active.
The other pluginâs start function gets the correct path now as parameter:
You could also offer a custom class load function in the base plugin. The basic idea here is: Do not let other plugins guess a path.