I am building a plugin that I hope to eventually put on Envato CodeCanyon.
Currently I am creating functions of the form mypluginname_action
. This is quickly becoming silly as I have to do that a lot. I’m thinking of using PHP namespaces, but I’m worried that there might be a reason why I shouldn’t.
- Are namespaces compatible with WordPress and Envato’s coding standards?
- Can I use namespaces in the PHP versions that I should be supporting?
- Are there any professional theme/plugin makers who make use of the namespace feature? If not, why not? Are there any common pitfalls with using namespaces?
I am well aware that I can research all of this myself, and of course I will, but as I’m early in development, at this point I’m hoping for a quick answer from more experienced people who might have already looked into this.
I appreciate any thoughts on this.
3 Answers
You can totally use namespaces in your project/theme/plugin!
The only drawback is that you introduce a PHP 5.3 dependency, while WordPress itself only requires 5.2.4.
I guess in 2015 this is not a big issue, even when distributing a plugin to a wide community (opensource or envato).
Roots team is using namespaces in their themes, plugins, etc: https://github.com/roots/sage