Themosis — WordPress meets MVC

Chigozie Orunta
4 min readJan 30, 2020

Over the past few years, I’ve found myself building more web applications using WordPress, partially because of its of ease of use and perhaps more because of its strong documentation.

In the early days, WordPress was originally designed for building blogs and small forums and it mostly passed off as nothing but a mere design tool for building simple websites to most programmers.

As time went on, more programmers began to see the possibilities of building simple applications using WordPress, when they noticed that it had most of the trappings of a basic framework (authentication, user roles, data sanitation and so on).

Perhaps the greatest limitation or hesitation to building web applications using WordPress by most programmers was that it lacked a strong framework that employed an MVC approach, which most developers had become accustomed to in building scalable web applications.

Enter Themosis!!!

Themosis is a web development framework designed to help you develop websites and web applications faster using WordPress. Themosis helps you structure and organize your code and allows you to better manage and scale your WordPress websites and applications.

Now you can declare WordPress or custom routes, controllers, models and views to build your application in WordPress. Using Themosis, you can build your templates using pure PHP, the Blade engine or the Twig engine. It even gets better, you can install Themosis and access amazing php packages using Composer.

Installing a new themosis project using composer is as easy as running a simple command from your shell terminal.

$ composer create-project themosis/themosis your-project-name

So if you’re still wondering if you should proceed with using Themosis for your next WordPress web application, then here a few more reasons why it might be your next choice:

1) Data Validation

Themosis comes with an Input Class that helps you retrieve all submitted data. You can pass an array of validation rules that can be used to ensure that the submitted data is the correct match.

$data = Validator::multiple(Input::all(), [
'field-name' => ['alnum', 'min:5'],
'age' => ['num', 'min:18', 'max:65'],
'website' => ['url:http, https'],
'email' => ['email']
]);

2) Routing

The Themosis route system allows you to define WordPress routes as well as custom ones. It extends the Illuminate/Router package providing extra features like group, controller namespace, middlewares and more.

Route::get('users/{name}', function ($name) {
$user = Users::getByName($name);
return view('account.profile', ['user' => $user]);
});

3) Authentication

Currently, Themosis has no way of authenticating users due to its lack of authentication middlewares, however with the help of “wp-kit/auth” component, we can achieve this by providing a UserProvider that integrates directly with WordPress to authenticate users.

You can install this via composer in the root of your Themosis installation.

$ composer require "wp-kit/auth"

The “wp-kit/auth” component comes with AuthenticateUsers Trait which can be used inside Controllers, just like in laravel.

namespace Theme\Controllers;use Themosis\Route\BaseController;
use WPKit\Auth\Traits\AuthenticatesUsers;
use WPKit\Auth\Traits\ValidatesRequests;
class LoginController extends Controller {
use AuthenticatesUsers, ValidatesRequests;
protected $redirectTo = '/';
public function __construct() {
$this->middleware('guest')->except('logout');
}
}

4) Templating

Themosis gives you the option of building your templates using pure PHP, the Blade engine or the Twig engine.

@extends('layouts.main')@section('content')
<h1>Account</h1>
<p>Welcome {{ $name }}</p>
@foreach($posts as $post)
<h2>{{ $post->post_title }}</h2>
@endforeach
@endsection

5) Pagination

Again Themosis falls short here as it seems to lack this feature, but thanks to a simple package called “djgadd/themosis-pagination”, we can implement this as well into our Themosis applciation.

Themosis Pagination is a package for the Themosis framework that implements some basic utilities for pagination to make it a little easier to work with (rather than being bound by WordPress’ markup and classes.)

To install via composer, simply run into the root of your Themosis application folder.

$ composer require djgadd/themosis-pagination

To read more about this, you can follow the link here.

6) WordPress (Custom Post Types, Taxonomies, Metaboxes, Custom Fields…)

If you have been building themes and web applications using WordPress, you may have noticed the need to constantly define custom post types, retrieve meta values for various post items and so on.

With Themosis, you can now quickly set custom post types, custom taxonomies, metabox, custom fields, administration pages, settings and more with built-in classes.

$books = PostType::make('books', 'Books', 'Book')->set();
$slug = $books->get('name');
Metabox::make('Details', $slug)->set([
Field::text('isbn'),
Field::collection('gallery')
]);
Taxonomy::make('authors', $slug, 'Authors', 'Author')
->set();

7) 404 Error Handling

Themosis provides WordPress routes based on the WordPress template conditional tags. One of the available route conditional tags is the 404 route and this comes in handy when define 404 Error landing pages.

Conclusion

Themosis comes with many other amazing features such as actions, filters, helpers, widgets, containers, providers. To be honest, this article doesn’t cover exhaustively every aspect of the Themosis framework and its best you try it out for yourself to see its capabilities.

In my own opinion, I think its worth the try.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet