WordPress: Simplifying plugins and themes developments


WordPress

In conjunction of my previews post, that you can find here, we will see how to simplifying plugins and themes developments using a framework and a template engine.

Developing plugins with Herbert

Herbert is a WordPress plugin framework that provides a structured and standardized approach to building plugins. The framework aims to keep business logic separate from template code, so that back- and frontend developers aren’t tripping over each other. Herbert utilizes Composer to handle the framework’s dependencies. Template code is stored in views, which uses the Twig PHP templating engine.

How to?

The complete guide is available in the official website at the next page:

Getting Started

Theming with Twig And Timber

WordPress is a great platform and it’s as versatile as a platform can be. Proof of that is that it currently powers more than 23% of the internet as we know it. Historically though that has not always been the case and there’s one thing that made WordPress stand out: Themes.

The WordPress theming industry is pretty large and everyday we see new businesses pop-up, offering their own themes. The choices are practically limitless and you can find whatever you need.

One of WordPress’s strong points is also -in my opinion- its weakest point. WordPress use old and deprecated PHP stuff, and a mixing of PHP/HTML for is themes.
Some CMSs in order to address that problem have decided to make things a bit better for their developers and use and MVC approche to separate data and view models, using a real templating language for their templates.
By examples, Drupal and Laravel both work with Symphony, which in turn utilizes the twig templating engine.

Installing Timber

Let’s now see how to install Timber using our composer.json file from my previous post. The only things you need to do, is to require the timber-library using the next command line:

composer require wpackagist-plugin/timber-library

How to?

Without create an other post about using Twig into WordPress, I prefer refer to you this great article explaining everything your need to know:

Simplify Your WordPress Theming With Twig And Timber

Bonus: Debug bar

The team being Timber plugin has also developed a Debug Bar using the WordPress Debug Bar . Once installed, the Timber Debug Bar gives you access to the current template name, its absolute location on your server and the full contents of the context (array) sent to the template.

To install the Timber Debug Bar, execute the next commands:

composer require wpackagist-plugin/debug-bar
composer require wpackagist-plugin/debug-bar-timber