Herbert: A New WordPress Plugin Framework

WordPress plugin authors have a great deal of liberty when it comes to structuring and organizing their code. There’s no prescribed file structure, so when you look under the hood of a plugin, you often need to poke around a bit to find out how the author is organizing things.

Jason Agnew found this to be confusing when he went to build his first WordPress plugin. Agnew is the technical director at Big Bite Creative, located in Middlesbrough, England. He often collaborates with both front and back end developers on projects, which drove him to find a better way to write plugins that are organized for multiple team members.

This week Agnew introduced Herbert, a new open source framework for building WordPress plugins. “We believe the current approach to building plugins is unorganized and difficult to understand,” Agnew said. “It makes working in teams or taking over from a previous developer time consuming. Its early days for Herbert but our aim is to solve this.”

Prior to creating Herbert with his team, Agnew did his homework to see if there was an existing tool to solve this problem. He discovered the WordPress Plugin Boilerplate project, but determined that it wouldn’t work for his agency’s needs. “Although WPPB would be a great starting point, it seemed best suited to the quick development of smaller plugins,” Agnew said. “We needed something more suited to scale.”

He checked out some of the most popular WordPress plugins, hoping to find a common thread among them for a semantic, structured method of plugin creation. “To our surprise, there wasn’t any sense of uniformity or consistency of implementation among them,” he said. At that point, he rallied his team to write their own WordPress plugin framework.

The open source Herbert project was born out of this effort. The framework aims to keep business logic separate from template code, so that back and frontend developers aren’t tripping over each other. “It offers a file structure to keep your code organised, with a solution as simple as all your routes belonging in the plugin/routes.php file,” Agnew said. “It no longer ties you or your development team to the WordPress Database Object ($wpdb), allowing you to use the power and effectiveness of Laravel’s Eloquent ORM to handle your database queries.”

Herbert utilizes Composer to handle the framework’s dependencies. Template code is stored in views, which uses the Twig PHP templating engine. The framework may not be everyone’s cup of tea. However, if you like separating your code into routes, views, and controllers, then Herbert may save you some time when spinning up new plugins.

The Big Bite Creative team plans to maintain the framework and will add plugin examples in the future. “We plan to introduce an interface to the WordPress post object for Eloquent, along with tests for your code,” Agnew said. They are also considering adding a WordPress-specific frontend framework to work alongside Herbert. The project is open to contribution, so feel free to fork Herbert on GitHub and send code back to the team.