Not a perfect one, but I have one case that is close to an example:
You see that if( kirby()->plugin('modules') )?
Yes, I have support for your plugin in one of my plugins now.
Anyway, in this example I check if the Modules plugin exists in order to see if I should allow registry on that type. If the plugin is not active, it should skip this step.
Why it’s not a perfect example
I know that if the Modules plugin is active if it exists because I force load all the plugins before mine. That’s why it’s not a perfect example.
Why the suggested feature
I feel like it’s two functions in one. If I just want to check if a plugin has loaded, I also need to load that plugin. It’s like atoms, I can’t measure them without changing them (Observer_effect).
But if you don’t see any real case of the need for breaking out the conditional function, I guess there are no need for it. Maybe I should get back to this when I have a better example of a real case?
That’s because it’s not a public API; it’s an internal method with its own idiosyncrasies.
Kirby does not use “private” much or at all in classes. Also the code style favors short nouns rather than long method names. So one would be forgiven for thinking that a method is a generic and public tool, when actually it’s an internal and rather specific tool. So I consider that if it’s not detailed in the docs, it’s a private API. ^^
Won’t work if you have plugins installed with Composer though.
Also it might not work depending on loading order. That’s how the plugin’s main PHP script is included and the $kirby->plugins array is populated:
That’s true. But code that is loaded with Composer is not a Kirby “plugin”. Kirby will never be able to provide an API for them.
That’s correct, but it’s the intended behavior of such a “plugin is loaded” method. If you’d like to know if the plugin will get loaded, you’d need the “plugin exists” method.
In the Twig plugin (v3), I only define classes and offer a static method (Kirby\Twig\Plugin::register) that uses the Registry and includes the plugin’s helper functions (that last part could be done by telling Composer to require a script, in addition to autoloading; but I like having it all in one place). Usage is fairly straightforward.
Well, but that’s something the plugin needs to support. It won’t work to include plugins in the plugins array automatically without some manual action by the plugin and/or the user.