I have been struggling with building on top of WordPress (WP) for as long as I can remember. One of the biggest development problems is figuring out whether you should do things the WordPress way, or completely hijack the request pipeline and design your own custom solution.
Prior to really understanding WP, I was more inclined for the latter approach. I consistently crowded the web root with a myriad of randomly named folders and files never following a particular pattern. Obviously, this propagated an immense amount of technical debt. A new developer would have no chance of understanding what I did without many hours of code inspection and frustration. There has to be a better way.
One of the better options, in my opinion, is a marriage between the WordPress way and a commonly understood development framework like Model-View-Controller (MVC). By following WP coding practices, you get a clean and organized file structure, and you can leverage cool things like short codes, custom post types, custom taxonomies and filters. Bringing MVC into the mix then provides the developer with a clear and consistent programmatic framework to structure (and separate) views from business logic. A pattern will help prevent the countless spaghetti-coded plugins that currently litter the WordPress.com plugin directory.
There are some more full-fledged WP MVC plugin solutions available for download, but I wanted something simple and light that developers could start custom development projects from. This is a boilerplate and is only intended for programmers. Documentation is sparse, but hopefully a MVC-minded background will help. Download instructions are below:
- Unzip the “mvc-shortcode-boilerplate” archive and move folder into your WordPress instance under wp-content -> plugins.
- In the WordPress administration site, click on Plugins and activate the MVC Shortcode Boilerplate plugin.
- To see the newsletter demo, create a new page and add this shortcode, [mvc_shortcode_registration_form], to the body.
- You can also manage submitted registrations in the administration-side by clicking on “Registrations”.
If this boilerplate is worth pursuing, I would like to make it modular and integrate the following:
- Active Record
- Page template and widget support
- AJAX routing
- Data types for Models
Also, if any developers are interested in making this an open-source initiative, please email me.