Recent Changes to generator-plugin-wp

I last went over the features of generator-plugin-wp in May and a lot has changed since then! There are three more sub-generators (and more on the way), the JavaScript workflow is improved, PHPUnit tests are built in for the main plugin generator and all relevant sub-generators, and the PHP include workflow is easier.

New Sub-Generators

Since May three new sub-generators have been added CPT, options, and widget. If you missed it last time: a sub-generator is a secondary generator that can be run on a plugin that was previously generate by generator-plugin-wp. So if I wanted to add a feature to a plugin I’m working on I could run yo plugin-wp:cpt book to add a new include file to my plugin that creates a book CPT.

The CPT sub-generator adds a new php class to the plugin which extends CPT_Core and by default includes CMB2 fields for the new CPT.

The options sub-generator adds a new php class which creates an admin options page with CMB2 available to build it out.

The widget sub-generator adds a new php class with the skeleton code to create a widget.

Using these sub-generators in addition to the previously available include, CSS, and JS sub-generators brings the speed of building out your plugin to a whole new level!

Improved JavaScript Workflow

The JS sub-generator has also been improved. If you read my previous post Modernizing Your WordPress JavaScript, you will know about using Babel and browserify-shim with Browserify to give the best development experience and end product for your plugin’s JavaScript. This workflow is setup automatically when you run yo plugin-wp:js in your plugin directory and select Browserify!

Unit Testing

Unit Testing is great, but unit testing with PHP and WordPress can be confusing at times to get setup. Now generator-plugin-wp includes tests by default whenever you create a new plugin and adds more tests with every sub-generator! Running the tests is as simple as running ./bin/ from the main plugin folder in your development environment with your dev database details, and then whenever you want to run the tests, just run phpunit from the plugin’s main folder. For more information on unit testing your plugins check out my previous post.

Improved PHP Include Workflow

Previously whenever you ran any of the PHP sub-generators (include, CPT, options, and widget), you had to manually add the new class to your main plugin class so that it would be included. With 0.9.0 any plugin generated after upgrading to the latest version of generator-plugin-wp will automatically add a statement like $this->admin = new CGS_Admin( $this ); so that the new include’s code is run without needing to make any changes to the main plugin class manually.

Coming Soon

We aren’t done yet! Coming soon we have a couple of new sub-generators: a Simple Page Builder sub-generator which will streamline the integration of Simple Page Builder into your plugin so you can easily add your own page builder parts, and a taxonomy sub-generator which will create a new include class which extends Taxonomy Core to allow for the easy addition of new taxonomies to your plugin.

If you have any ideas on more things that could make creating new plugins even faster please go to our GitHub Issues page or if you are feeling adventurous submit a pull request!


Have a comment?

Your email address will not be published. Required fields are marked *

accessibilityadminaggregationanchorarrow-rightattach-iconbackupsblogbookmarksbuddypresscachingcalendarcaret-downcartunifiedcouponcrediblecredit-cardcustommigrationdesigndevecomfriendsgallerygoodgroupsgrowthhostingideasinternationalizationiphoneloyaltymailmaphealthmessagingArtboard 1migrationsmultiple-sourcesmultisitenewsnotificationsperformancephonepluginprofilesresearcharrowscalablescrapingsecuresecureseosharearrowarrowsourcestreamsupporttwitchunifiedupdatesvaultwebsitewordpress