AndrewTraub
Expert
Super Volunteer
Member Likes (0)
What is the best practice for plug-in development - should it use a class or not? I always thought creating and instantiating a class was best but I'm halfway through Wrox's "Proffesional Plugin.." book and they seem to be pushing plug-in functions with prefixes that make them unique rather than classes. Any thoughts would help.
Andrew

Responses (5)
WPMU DEV Fanatic (joined October 2009) Likes (0)
Hi Andrew,
That's a good question and apart from tiny plugins, I've just assumed it's best to use class/object-oriented practices. I learned to program via Basic languages like Quick Basic and Visual Basic myself, so I'm still more comfortable with non-object-oriented development, but does the book provide any reasons for preferring one over the other?
I'll mention this thread to some of the guys over here to see what thoughts they have to share as well.
-David
Member (joined October 2010) Likes (0)
The books doesn't really mention it one way or another and there is one or two examples showing how to implement a hook or filter in a class, but otherwise they stick to using prefixes that are unique in their examples.
I'm comfortable with classes in c# and vb.net but haven't really done much with them in PHP.
Andrew
Member (joined August 2011) Likes (0)
I typically like to have a little bit of both. This depends on what the implementation on the front end will be but I will typically create a globalized class instance and then include a template functions file that has top level functions. So something like this.
Then the template functions file can house top level functions accessible from my theme if needed, and If you need to retrieve any information from the class simply use
I picked up this habit by looking at some of the wpmu plugins like marketpress.
Member (joined October 2010) Likes (0)
Thanks so much pro120 - +1 to you.
Andrew
Sales & Support Pro (joined March 2010) Likes (0)
That book does use some classes but I've taken their approach and worked out a system of generating a unique prefix. I use my initials and an acronym of the plugin.
For example, in my plugin Author Bio Shortcode all the function (and option) names start with the prefix "pj_abs_" to help avoid clashes.
If a function is to implement a hook or filter I try to use the hook name too. E.g. pj_abs_wp_head for a function that hooks into wp_head.
Thanks
Become a member