Introducing Forme - An MVC Framework for WordPress

Introducing Forme

I’ve been quietly working on Forme for the last couple of years, mainly to scratch my own day to day development itch over at Sanders Web Works, where I’m the lead dev. We’ve recently open sourced it over on Github and it’s about time I wrote a little introductory blog post about it!

In a nutshell - it’s an MVC framework built on top of WordPress. It borrows patterns (and libraries) from projects such as Laravel, Slim and Symfony to make the developer experience more modern and enjoyable. It’s inspired by similar WordPress projects such as Roots, Lumberjack and Themosis, but follows its own opinionated workflow.

It gives you a solid base to build WordPress plugins, themes and installations that are actually not a total spaghetti nightmare to maintain and work with - yes that’s an actual real possible thing!

spaghetti.gif

Spaghetti Monster Gif from Justin Gammon

Why would you even do this?

But, but… WordPress is a veritable dumpster fire of crappy code I hear you cry - why do you even need to use it in 2022? Just ditch it already. If you really need MVC (or ADR/DDD/whatever your architectural poison is), use the right tools etc.

Well yes, but… there are still plenty of projects where WordPress is absolutely the right choice.

  • WordPress has a vast ecosystem, including some very useful, stable and well thought out plugins amongst the morass - e.g. ACF, Formidable, and yes, even WooCommerce - although the less said about its templating the better 😬
  • It’s got very decent and thorough documentation over at WordPress Codex
  • It’s got an absolutely enormous developer community. See WordPress Forums and StackOverflow and everywhere else on the web.
  • Clients like it, are already familiar with it, and don’t need a lot of ramping up to get to grips with it - the admin UI does what it needs to do very well. It isn’t the biggest CMS in the world for nothing - and yep that’s also (very nearly) true for enterprise companies. Love it or loathe it, WordPress is essentially the web’s default.
  • And of course like any agency, we have our fair share of inherited and legacy projects. We definitely don’t have the time, budget or the bandwidth to convert everything to Laravel/Rails/NextJs/(substitute your favourite backend framework du jour here). Forme provides a refactoring path for us to make certain projects that possibly shouldn’t have been built with WordPress in the first place less painful to deal with, without having to push for a complete rewrite.

The point is, developers and agencies often have to use WordPress even for relatively complex domains. Forme helps make the development and delivery of those projects much smoother, and also ultimately much quicker.

Just as a counterpoint, Forme is probably overkill if you’re spinning up a simple blog or portfolio website for someone, but if you’ve got any kind of heavy custom business logic going on and WordPress’ global first approach just won’t cut it, it’s going to be worth a look.

skills.gif

via GIPHY

OK then, show me them skills!

So, what are the features exactly? A lot of the stuff you would expect from a modern MVC framework is there, such as:

…and plenty more. If you’re coming from Laravel or Symfony, you’ll feel right at home.

Two of the killer features that really speed up my own day to day work are probably the hook config yaml and the codegen cli.

The first of these provides a satisfyingly clear and centralised overview of all the WordPress actions and filters that our plugin or theme listens to. I find that it makes editing and reasoning about hook configuration way simpler than desperatley grokking for scattered add_action or add_filter calls and trying to remember what order the arguments go in.

As for the Forme Codegen, we get a useful and focussed set of command line tools:

  • boilerplate code/class generation - 🧰 make
  • hassle-free project scaffolding - 🌱 new and 🏗️ base
  • easy version updates including git tags and plugin/theme meta - 👊 bump
  • and even a simple docker development environment - ⛵ketch

Obviously I have skin in the game, but I actually enjoy WordPress development when I’m using Forme.

future.gif

Future plans

The Forme codebase is relatively stable at this stage, but I’m still very actively developing it, especially since I use it almost every day. Any patterns or features within specific projects I’m working on that I feel could be useful more widely often make their way upstream back into the framework, as well as bug fixes and improvements.

I am planning on bringing in a bunch of specific new features over the coming year, including a WordPress directory packaging solution via Box, and some kind of workflow and automated test case generation for PHPUnit, PHPSpec and/or Pest.

I’ll also be writing up some tutorials here on my code blog when I find the time, as well as trying to continuously improve the documentation.

Please give it a try and let me know what you think. And if you feel so inclined, I’m very much open to feedback and contributions.