WordPress’ Event-Driven Architecture vs MVC

So I was thinking recently I wonder which parts of Ruby I have been learning could apply to WordPress. More specifically we just started working with Rails which is a framework for Ruby, the two together giving us Ruby on Rails.

Ruby is our programming language. Rails is a framework that is neither a forward-facing web application nor a programming language. Rails is a library of ruby that allows us to expedite the application building process.

Ruby on Rails employs Model View Controller (MVC) which is a standard for dividing your code base on its function. The Model is the logic. The View is what you see when visiting a webpage. The Controller is an between that requests logic when needed and sends the appropriate view.

WordPress on the other hand is employing an event-driven architecture. Which can be visualized like this:


WordPress’s Event-Driven Architecture uses hooks to make changes at specified event triggers.

For instance when a webpage is called it will hit the head tag. In WordPress you could write an Action hook to say send in this meta description when the head tag is called. A meta description being that little snippet you see below a search result in google. WordPress also offers a secondary type of hook called a filter that is commonly used for manipulating data.

WordPress has similar pieces to Rails but a common theme my research to compare the two of them was the sentiment: not to get too hung up on the comparison because the two do not really translate to one another.

WordPress uses MySQL as its database. The WordPress dashboard — which is WordPress — functions as the Application Layer. And templates are used to render views. There is a lot of commingling of functionality here that would drive a MVC programmer a little mad.

I found this quote by Tom McFarlin that I found helpful in beginning to sort out the differences:

“Simply put, frameworks are not applications, foundations are applications.

Just because a web application can be built using WordPress does not make it a framework. It’s a foundation. It’s an application unto itself that can be extended into further applications.”

For the time being that is pretty much all I wanted to get down on paper (blog paper). A short and early exercise into comparing something familiar to me (WordPress) with the approach to web applications that I am learning (Ruby on Rails).

I leave you with a funny little middle ground I stumbled upon. There is a plugin out there that allows for a MVC framework within WordPress. As I looked through how to setup the plugin, the PHP used to install the basic framework is extremely similar to Ruby. Take a look: