TGMPA / TGM-Plugin-Activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install, update and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference bundled plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet.
http://tgmpluginactivation.com/
GNU General Public License v2.0
1.75k stars 431 forks source link

Add a class_exists to check if plugin is active (like is callable) #754

Open Tofandel opened 5 years ago

Tofandel commented 5 years ago

This PR adds an option 'class_exists' to check if plugin is active (like the is_callable option)

jrfnl commented 5 years ago

@Tofandel Hi Adrian, thank you for your willingness to contribute. Could you please explain what this adds what you couldn't already do with is_callable() ?

Every class should have at least one public method otherwise it cannot be instantiated. Using that method with is_callable, as in passing someClass::SomeMethod as a value to the array, should work already.

Tofandel commented 5 years ago

@jrfnl Hello, well is callable will work only with public static functions, already instantiated objects's private methods (which you cannot do if the plugin is inactive) or public methods BUT NOT THE CONSTRUCTOR

So this would add the possibility to check if a class exists which you cannot currently effectively do with is_callable if only a constructor is available and no other public methods within the class (which is usually the case with well structured plugins)

Thanks

Tofandel commented 5 years ago

We could also argue that for an hypotetical plugin which only add_filters and actions with anonymous functions and have no class defined or function whatsoever it would be very hard to check that they do exist, but they may define a constant with their version or whatever. Then an is_defined option would also make some sense (even if this is very unlikely that there is not a single function or class) but that would give the entire flexibility of checking whether or not a plugin indeed exists with different methods that can fallback on each other since the condition is made with an 'or' statements

Since it doesn't break anything and just gives some flexibility I wouldn't see why not include these options What do you think ?

By the way I didn't had any answer on the 'mo files are not well generated' issue, should I make a PR with all the mo files regenerated ?

Edit: Added is_defined to the PR following the logic