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 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!
yo plugin-wp:js in your plugin directory and select Browserify!
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/install-wp-test.sh 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.
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.