Answer the question
In order to leave comments, you need to log in
What is the best way to write procedural or OOP plugin code in wordpress?
I am developing WordPress plugins. What is the best way to write plugin code in wordpress with procedural or OOP classes?
What are the pros and cons?
The client wrote:
"Do not use heavy OOP (Object Oriented Programming) Procedural is better."
Your opinion and the opinion of people who have been doing this for a long time are interesting, so as not to make mistakes in the future and go the right way.
Thanks :-)
Answer the question
In order to leave comments, you need to log in
Recommended / best practice - OOP. What patterns to use is up to you. Singletons are a very controversial approach, some cannot break away from it, others feel sick.
But OOP is only for big plugins. For example, if you write a lot of custom functionality for the site (in the form of a plugin / s), or one relatively large niche plugin, we use OOP. If the plugin is small and not complex - procedural. It makes no sense to build a high-rise building where there are enough huts on the shore.
And in any case, if the plugin implies convenient methods for outputting content / results of its work into templates, then it is worth writing your own template tags for the convenience of end users - a good practice. It is much easier for them to use the familiar format, for example, the custom function my_get_post_views(), which displays the number of post views, instead of calling a class method. The function itself, in turn, is only a wrapper for this call, but it is more understandable and convenient for ordinary users.
Best practice when developing on wordpress is OOP and singleton. Further - at your discretion. The only exception is when you have a couple of functions and one hook, roughly speaking. There 's a lot of good advice here, most of it general.
In no case do I recommend procedurally, this is the way of all drupals, it does not give any advantages and it looks / refactors / reads terribly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question