Object Oriented Programming (OOP) of a WordPress plugin

When we (Morning Train) are coding a plugin for WordPress, we always use Object Oriented Programming (OOP). OOP is often the best way to code, because it makes complex code easier to develop, read and maintain. When coding a WordPress plugin, there are even more good reasons to use OOP.

Why is it important to use OOP for WordPress plugins?

There are many good reasons to use Object Oriented Programming for WordPress plugin development.

First of all, we have all the normal reasons for using OOP when developing complex and simple systems. Some of them is:

  • OOP makes the code more structured
  • It is easier for other developers to understand the code
  • It is easier to develop separate parts of the system
  • You can extend functionality really simple
  • It makes debugging easier
  • The code becomes easier to maintain

But when we develop a plugin for WordPress, the most important reason is:

When developing a plugin for WordPress, every single function has to have a unique name, also compared to every other plugin. This means, that function names becomes really complex, like "myWordPressPluginName_getUser()". If we use OOP when developing, we can avoid this problem.

Beside that, it is best practice to user Object Oriented Programming, so that is what we do, ALWAYS! 

How to use OOP when developing a WordPress Plugin?

Based on the "WordPress Plugin Boilerplate" by Tom McFarlin, you can easily start building you own OOP driven WordPress Plugin. He has created a really god structure, that can serve as a starting platform and inspiration.

It is important, that you only use the files, that is necessary for your plugin, so use the WordPress Plugin Boilerplate as inspiration and guide to the structure, when you are developing.

ms@morningtrain.dk'

Martin Schadegg Rasch Jensen