I’ve talked quite a bit about my thoughts on using WordPress for web application development. Specifically, I’ve shared:

During the State of the Word 2012, Matt discussed the past, present, and future of WordPress which included WordPress being an “app engine” of sorts. Some time ago, I stumbled across an article by Matthew Eppelsheimer in which he discusses his team using WordPress as just that.

Specifically, he says:

The WordPress platform essentially manages content and authentication for us, gives us frameworks to build custom UI and our own functionality, and offers extra features in the form of plugins developed by a large community. It gives us everything we need to rapidly build our own custom tools that fit our own process, style, and needs.

Interesting, isn’t it?

Obviously, I’ve been a fan of treating WordPress as such for some time, but I’ve never really shared how I’ve viewed various features and parts of the API for actually building applications.

Since I’ve recently wrapped up a project where we did just this, and since I’m currently in the middle of building one that’s following suit, I thought I’d share a few notes on my approach for building web applications with WordPress.

Building Web Applications with WordPress

First off, I want to state that I’m not at all dogmatic about these opinions. In fact, I’d go as far as to say that I have strong opinions, weakly held.

By that, I mean that although I believe that this particular approach works well, I could be swayed given other great opinions, approaches, and/or thoughts with evidence to back them up.

With that said, here’s how I generally view WordPress as an app engine:

Clean API

Building Web Applications with WordPress - Clean API

The first thing to mention is that I believe WordPress, relatively speaking, has a clean API. I’ve built applications using .NET, Rails, and raw PHP, but I’ve never had such an easy time picking up an API.

I’ll be the first to admit that experience is the best teacher so perhaps I cut my teeth on these other platforms, but I do believe that the documentation for WordPress is just as rich as many of our other options.

Furthermore, I think that once you understand a few key features (such as the Page Lifecycle and Actions and Filters) that you’ve got a relatively solid grasp of how the platform operates as a whole thus making it much easier to being quickly implementing custom functionality.

User Management

Building Web Applications with WordPress - User Management

Perhaps the largest piece of boilerplate code for web applications is user management. Think about it: nearly every single web application requires you to register either using their native interface, Facebook, Twitter, or Google, and then requires you to use said credentials to authenticate and use the application from that point forward.

Out-of-the-box, WordPress not only includes solid user management, but it provides a solid API for managing them, and does a good job of separating users from their roles and capabilities so that you can easily (and programmatically) manage your users.

Model-View-Controller

Building Web Applications with WordPress - MVC

I think that the two main patterns developers opt to use when implementing web applications is Model-View-Controller or Model-View-ViewModel.

Personally, I’m a fan of MVC as it maps to my mental model of how the web works, but because of the way WordPress is architected, you can’t implement the pattern in its purest form.

That said, I have taken similar approaches in a few projects.

Models

Historically, models are meant to map information to and from the database into an object with attributes. Although it’s absolutely possible to do this using custom tables, I try to to leave the natural database schema intact and leverage the existing API for that.

So, for models, I’ve found myself often using Custom Post Types.

Kind of weird, isn’t it? I’ll be the first to admit that I think of custom post types as being used to generate views (which I’ll cover more momentarily), but when you think about the fact that most model-like data – that is, pages, posts, and so on – comes back to “Posts,” you can easily shift your thinking into how this can be used for generic models.

We have total control – from what a custom post type will support all the way through its URL structure – over what defines a post type. This means that we can give the post type a specific model name (think something like, say, Goals or Questions), and then wrap any other attributes into its meta data.

Views

Views should be the most straight-forward aspect of building applications with WordPress. Personally, I view it as two components:

  • Templates
  • Custom Queries

Through the use of custom templates, we’re able to build any kind of view for representing our data, and if we’ve used custom post types, taxonomies, or a combination of any other feature of WordPress, we can take advantage of custom queries for pulling back said data.

Building views using WordPress is arguably one of the simplest aspects of building web applications with WordPress.

Controllers

This is where the MVC paradigm loses itself in WordPress because there are no true facilities for writing controllers; however, it’s completely possible using custom hooks and functions to emulate them.

For example, controllers generally include the following functions related to models:

  • Create
  • Read
  • Update
  • Delete (or Destroy)

By using a combination of hooks in certain parts of the page life cycle, and writing functions for the above operations, you can give WordPress the ‘controller’ logic that most other MVC-based frameworks offer.

Now, I’m not claiming that this is the best or the right way to do it, but it’s a way that I’ve used in a number of different projects.

Business Logic

Building Web Applications with WordPress - Business Logic

For those who follow a domain-driven approach to building applications, you know that one of the key components in solid engineering is keeping the business logic separated from the rest of the application.

That is, whatever rules surround, say, a given model should be documented and contained in their own set of functions.

I think this is one of the strongest aspects of WordPress because it naturally relies on functions.php for a lot of custom functionality. At the most basic level, this means that we need to keep our business rules in this file and out of any type of view logic.

But I’ll go one step further and say that business rules can be kept in a separate PHP file for the sake of organization, included in functions.php, and then serve to provide an API-of-sorts that views can actually call.

This keeps the rules separated from the rest of the application, makes them easier to read and maintain, and it keeps our views clean by allowing us to call down into methods rather than littering our view logic with custom queries, validation code, and so on.

URL Rewriting

Building Web Applications with WordPress - URL Rewriting

Finally, we live in an age where URL’s are significantly more important than they used to be. Some argue that this is for SEO purposes, others argue that this provides a clean and easy way to navigate an application, and some argue both.

Whatever the case, WordPress provides strong URL rewriting. Out of the box, you have a variety of options from which to choose, but we also have the ability to completely customize our URL rewriting schemes using the built-in API functions.

…and more!

Building Web Applications with WordPress - There's More

Of course, there’s even more to it than this. I’ve not actually covered taxonomies and how they can also be used to represent a type of model or even grouping similar models, nor have I talked about how to organize various assets – be it images, JavaScript files, third-party libraries – and so on.

But my overall point remains: Building web applications with WordPress is not a pipe dream and I say that we’re at a place where we can do so now. I just think that it requires developers to step up and start thinking of the platform as a viable alternative to some of the other frameworks and platforms that are out there.

And as I said at the beginning: These are just my thoughts. For those of you who have worked on similar projects, or who have completely differing views, or who have something to share, do so in the comments.

This is clearly a topic I enjoy discussing.

Category:
Articles
Tags:

Join the conversation! 36 Comments

  1. Hi,

    very nice article. I also want to think more about using WordPress as an Application Framework. To get into this I bought two PHP books (they didn’t arrive yet) and I will study and practice PHP within WordPress. I think that with this approach I can map basic php practices to the WordPress way of doing things.

    I like the usual php frameworks, but with WordPress with have much more things ready. We really must try giving to WordPress a chance to be an application framework.

    Thanks,
    Thiago

    • Thanks for the comment, Thiago!

      One of the things that I always tell aspiring WordPress developers is not necessarily to try to get a full grasp on PHP before jumping into WordPress.

      Sure, it’s important to know the language, but I think that having a basic understanding of things such as conditionals, loops, variables, and functions can go along way with getting started. Eventually, you’re going to pick up things simply by working on projects.

      While you’re going through those books, don’t forget to go through the WordPress Codex either – good luck! :)

      • Thanks…

        I’m already reading a WordPress book and have already created some plugins and themes :) So, now with your answer I’m sure this is the way ;)

        Hey, just an opinion about the MVC approach. Really, I’m not sure if the MVC that we use on rails and other usual app’s is good as the approach already used on WordPress, really.

        The concepts of MVC is very beautiful to read and apply, but in practice in many usual app’s people usually don’t change the views or the skin of their application. Also they never rewrite the views or controllers. So, I think that MVC teach some “plug ability” that we never use.

        In WordPress we don’t have the usual MVC, but in practice we have themes and skins… the views change while the core and plugins are the same. Different from the MVC from other frameworks, in WordPress the “plug ability” really works and it’s not just theory.

        Like you I also like how our code get organized when we apply MVC, but sometimes it’s better to take easy about what best practices we will continue to use when changing our development platform :)

        What Do you think about?

        • Ah, I don’t really think there’s a “best” or a “right” way to build things with WordPress. I think it’s more about solving the problem at hand.

          Some projects I’ve worked on have just gone with the usual action/filter/function approach with page templates; others have had more involved solutions such as organizing files like models, views, controllers, assets, etc.

          So, for me, it’s not so much about shoe horning a problem into a pattern. It’s about solving the problem – sometimes a pattern works, sometimes it doesn’t. When it doesn’t, don’t force it.

  2. Do you have any examples besides the ones that Matt used in his State of the Word talk of applications that have been build on WordPress?

    • Writing a plugin is essentially “writing an app on WordPress,” the only difference is that this doesn’t significantly change to core use case(s) for the WordPress platform itself.

      In a sense, WordPress has been a candidate platform for web apps for a while.

      I think what you’re saying, Tom, is that as WordPress has matured, the breadth of web app possibilities for which it would be a well-reasoned candidate has widened significantly. To that point I thoroughly agree!

      Looking at the entire project life cycle, the development and engineering piece is but one consideration. Some others that are easy to overlook are:

      Time-to-market — Availability (mind-numbing volume) of open source code libraries & plugins fast-tracks development.
      Reliability — Open source code is typically tested-and-peer-reviewed. Great for your subcomponents & infrastructure.
      User Adoption — WordPress is one of the most familiar admin panels for non-technical end users on the market.
      Maintenance — Cost and availability of existing WordPress talent continues to grow and strengthen.
      New Development — Again, community and resource pool for talent is available and reasonably priced compared to competition.

      It’s a good time to develop on WordPress.

      • It’s a good time to develop on WordPress

        Definitely agree on this (of course, I think it’s obvious given what I share here)! That said, I think there are some pitfalls to be mindful of to your points above:

        Time-to-market — Availability (mind-numbing volume) of open source code libraries & plugins fast-tracks development.

        Out-of-the-box, WordPress offers some serious boilerplate code to help us get started (like the role and capabilities mentioned above).

        But there are a number of “developers” who franken-theme work together and say they’ve built something from the ground up. Bundling plugins and a theme together isn’t development, and simply leveraging open source for this can be dangerous especially when you’ve not vetted the plugins you’re shipping with your work.

        Reliability — Open source code is typically tested-and-peer-reviewed. Great for your subcomponents & infrastructure.

        Usually, this is the case. I think this is one area in which WordPress plugins and themes (specifically the free ones) have suffered, but it’s definitely getting better.

        The premium themes are generally of higher quality, but even some premium plugins could stand to be improved.

        User Adoption — WordPress is one of the most familiar admin panels for non-technical end users on the market.

        Amen to this…

        Maintenance — Cost and availability of existing WordPress talent continues to grow and strengthen.

        …and this

        New Development — Again, community and resource pool for talent is available and reasonably priced compared to competition.

        I think that this is a budding area. The experience level of people varies and I respect those who are more honest about what they do know rather than trying to fudge knowing more than they really do.

        But that’s not a problemn with WordPress. That’s an “HR” problem :).

    • Hey John, I didn’t intend that comment to be a response to your question.

      I agree… would love a list of web apps, built on WordPress, that offer a significantly different experience than the original intent of WordPress.

    • Konstantin linked up one in his comment.

      I’m hoping to blog about a few things that I’ve also done recently, but I’m waiting for one of the larger projects to wrap up so that I can discuss it. Specifically, there are two larger ones that I’m working on – one of which probably won’t be complete until next year, but it’s the one that I’ve taken an MVC approach towards building.

  3. Tom,

    I only started following your site in Google Reader a few weeks ago, but it’s fast becoming one of the few I really look forward to reading. As we both know, there are a plethora of WordPress related sites out there but very few cover topics the way you do. You are very good at mixing the small tutorials with the grander ideas that really need to be discussed.

    This “series” on WordPress as a Framework is incredibly important for our community. Like most, I started down the WordPress path looking for a blog or site creation platform but noticed very quickly that it holds many advantages when viewed as an app development framework as well. I too suffer from the stigma around themes and plugins, and your previous articles make a great point about insufficient and misleading terminology creating a lack of understanding regarding their true power.

    In particular, your discussions about development platforms being viewed in the context of how closely they adhere to an MVC pattern is refreshing and (I think) not talked about NEARLY enough. It’s unfortunate that an idea can gain so much traction and such a large following that it can blind others to the fact that there are other ways of designing software. Just because MVC works, and works well, does not mean there are no other alternatives. I find the true beauty of software development lies in the endless possibilities it offers, not in it’s strict adherence to existing best practices. If your app can be built properly on an MVC architecture that’s wonderful and it will help your development and maintenance; but if your app can or even needs to be designed around a different paradigm it doesn’t mean it’s wrong. Just different.

    That’s how I view WordPress as an app framework: Not wrong, just different. And different is good.

    Thank you for taking the time to write articles that give the rest of us a few minutes of enjoyment and enlightenment.

    • I only started following your site in Google Reader a few weeks ago, but it’s fast becoming one of the few I really look forward to reading. As we both know, there are a plethora of WordPress related sites out there but very few cover topics the way you do. You are very good at mixing the small tutorials with the grander ideas that really need to be discussed.

      Thanks so much – this is definitely one of the nicest comments I’ve received on the blog and am glad you’re digging the content. It’s exactly the kind of stuff I’m aiming for, so I’m glad to hear that others are enjoying it!

      In particular, your discussions about development platforms being viewed in the context of how closely they adhere to an MVC pattern is refreshing and (I think) not talked about NEARLY enough.

      This is one of the topics that I have a lot of opinions on and that I enjoy discussing, but writing longer articles takes time and I try to balance it out by providing shorter posts around various projects and tips.

      All that to say, this won’t be the last time that I talk about this particular aspect of developing applications on top of WordPress.

      And to your point – I agree that WordPress “isn’t wrong, just different.” The thing is, I think that we’ve been stuck in somewhat of a rut when it comes to application frameworks.

      The foundation for many of the things that we’ve seen are all the same – that is, MVC, MVVM, or something similar – but their implementations vary. These variations go from certain languages all the way to how opinionated they can be (thinking about Rails and its convention over configuration approach).

      Anyway, there’s more to come on this so I’m glad I’ve got others who are enjoying it and chiming in :).

  4. Nice post Tom! For anyone looking for more examples of web apps built with WordPress, here’s Foller.me — a Twitter analytics tool, built with Bootstrap and WordPress.

  5. Tom, can you elaborate on why you feel that using hooks is only a mechanism to “emulate” the MVC. If we view WordPress as an API and hooks as merely a mechanism to interact with that API, then I don’t see why the architecture isn’t able to behave as a full-blown MVC. What would a traditional MVC architecture consist of that is not being allowed here? Would definitely love some education on this area as I’m sure there’s more for me to understand.

    • This is a good question – I could probably stand to reword my thoughts up there, but don’t mind elaborating down here.

      So, to me, when it comes to building web applications using one of the many frameworks that are out there, the various aspects of the pattern are abstracted away from us. By that, I meaen that when we need to setup a model, a view, or a controller, then we generally setup a subclass of some other aspect of the framework and the details are taken care of for us.

      WordPress doesn’t offer that. Instead, we have hooks that allow us to provide mechanisms for implementing that, but it’s still very much a manual process.

      This isn’t a bad thing and I’m not arguing that it should be this way. I love WordPress’ flexibility, but if someone comes to WordPress from another framework and are expecting a certain level of work to be done for them, then they’ll be surprised.

      So anyway, yeah – they are mechanisms in that they offer that functionality, but it requires that we implement it ourselves.

  6. ManageWP is a good example of this – an entire SaaS based entirely on WordPress.

  7. Hi,

    I totally agree with this article. Now with 3.5 coming soon, we will be able to make use of Backbone.js with each WordPress install without having to manually add it. That helps to shift things to a more MVC view (from JavaScript at least).

    I have built two plugins to make using WordPress as a web application platform, and I think more can be done. We just need to shift our thinking away from blog engine to web based applications.

    • Yeah – I’m pretty excited about some of the new stuff coming with 3.5. I love the shift of further separating client-side logic and server-side logic as I think it makes over all development and maintenance easier.

      I’m interested in your plugin, too! Check out this post and let me know if you’d be interested in sharing more about it!

  8. Hey,

    today I was surfing the web looking for opinions about using WordPress as a framework. I read an argument that I liked. So, I thought would be good to come back here and share. Here it is

    http://stackoverflow.com/questions/4576062/to-use-wordpress-for-developing-a-web-application/13327456#13327456

  9. It’s a greet tutorial you share here and thanks for this
    I have a lot of thoughts on using wordpress as an web application framework
    i have already made a to do list with wordpress and that is easy with PHP and was easier with wordpress
    but can i ask you a question:
    Can I translate this article to Arabic and share it on my site??

  10. I have been using these on may client projects for such long time. Feels good to see these documented somewhere. WordPress is very powerful indeed!!!

  11. Hi! Im also very interested in WP as App Framework. My understanding is that the facilities WP has in benefit (templates, huge plugins, extreme extensability) isnt found any app frameworks I`ve seen so far.

    But for the sake of generating quality for business apps code base, I have done a little plugin that aims to structure and wrap WP and the Domain, in a framework-like fashion.

    Would be great to receive a feedback from you.
    https://github.com/thiagof/pwrapper

    • Hey Thiago – thanks a ton for the comment. I dig hearing from others who are looking at WordPress as a foundation for web apps. If I get a chance, I’ll take a look at pwrapper – thanks for sharing the link!

  12. Hello Tom,
    First of all, this is really great website, I’ve found a lot of interesting articles, just googling some things about WordPress development.

    Our view about WordPress as application development is similar, but technically different. I am building my own framework, I like the OOP paradigm and I find it more useful and clear than plain functions, so what I am building offers almost a full OOP experience which resembles the Front Controller pattern where every functionality of the plugin or theme, is treated as a dynamic object.
    I want just to simplify my code workflow with a “comfortable, useful, clear, organized” framework, and I think I will be able to achieve all of this at the end.

    An example I can share is that I am also willing to use WordPress as a backend application server for those web apps that need to share contents and metadata to mobile apps, so an unique administration panel for the customer to manage contents for two platforms. All of this will be achieved obviously through a custom plugin built on top of the framework being developed.

    WordPress can sure behave as a complex framework in the hands of that developers who want .

    P.s I’m italian sorry for my English, perhaps I made some error!

    • First of all, this is really great website, I’ve found a lot of interesting articles, just googling some things about WordPress development.

      Great to hear – I’m glad you enjoy it!

      I want just to simplify my code workflow with a “comfortable, useful, clear, organized” framework, and I think I will be able to achieve all of this at the end.

      That sounds cool – would be neat to see when you’re all done :).

      All of this will be achieved obviously through a custom plugin built on top of the framework being developed.

      Sure! There have been a few implementations of things like this before, and with the upcoming JSON REST API I think we’re going to see a lot more of it, too.

  13. Great think about web application development with WordPress. WordPress CMS use very simple………

  14. WordPress is a simple to use because you can easily insert plugin in your wordpress website. According to me building web application is little bit tricky for newbie developers but with wordpress you can easily build it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.