All plugins share a common scaffolding. This results in a rather large amount of boilerplate code. This has been recognized by several initiatives that aim to facilitate the kick-start of new plugins by providing some kind of initial framework to build your plugin upon. The one I always use is the WordPress Plugin Boilerplate.

Even with this framework, I felt that I had to spend quite some time every time I wanted to start a new plugin: adding the plugin name in all the proper places, cleaning files (if that plugin had no public or admin view), adding menus,… And since I like to abstract and automate everything, I’ve decided to create a small DSL (Domain-specific Language) that given a plugin definition generates an adapted installation of the WordPress Plugin Boilerplate ready to use.

You can check the DSL grammar and the generation templates from the WordPress Plugin DSL public repository.

The DSL is created with Xtext (together with Xtend for the code-generation templates).

Xtext is a framework for the development of domain-specific languages. With Xtext you define your language using a powerful grammar language. As a result, you get a full infrastructure, including parser, linker, typechecker, compiler as well as editing support for Eclipse, any editor that supports the Language Server Protocol and your favorite web browser.

Right now, the grammar of the DSL is rather simple but I plan to extend its capabilities as I detect more and more automation opportunities that server my own plugin development needs. See an excerpt of the grammar below

	'plugin' name=ID '{' globalinfo=GlobalInfo (options=GenerationConfig)? (admin=Admin)? (publicview=PublicView)?'}';

	'pluginName' pluginName=STRING
	'author' author=STRING
	'authorURI' authorURI=STRING
	'description' description=STRING;
	{Admin} 'admin' '{'  (menuitems+=MenuItem)* '}'; 

	'menuitem'  name=ID ':' type=TypeMenuItem ;
	NewMenuItem | ExistingMenuItem;	

	'new'('under' superMenu=[MenuItem])? '{' menuItemInfo=MenuItemInfo '}'; 
	'title' miTitle=STRING
	'pageTitle' miPageTitle=STRING
	('slug' miPageSlug=STRING)?
	('capability' miCapability = STRING )?
	('function' miFunction = STRING)?
	('icon' miIcon=STRING)?		
	('position' miPosition=INT)?;

A sample of a plugin grammar and the generated code is included in the repository.

Share This