Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

Tofandel
Copy link

@Tofandel Tofandel commented Aug 1, 2018

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

There is an is_callable to check if a function is defined but no class_exists, class_exists is more appropriate  IMO
@jrfnl
Copy link
Contributor

jrfnl commented Aug 1, 2018

@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
Copy link
Author

Tofandel commented Aug 1, 2018

@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
Copy link
Author

Tofandel commented Aug 1, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants