The best way to setup your WordPress custom plugins.
First of all, if you don't have it already installed on your system, install Yeoman using npm (we assume you have pre-installed node.js).
npm install -g yo
Than install the @wptools/generator-plugin generator globally on your system.
npm install -g @wptools/generator-plugin
Now you have access to the generator through yeoman this mean you can generate new projects anywhere by typing:
yo @wptools/plugin
The generator will ask you some questions for setting the project configuration parameters and once is done the new project will be created.
Inside an existing project generated with this generator you can also use many sub generators to go further in the project base prototyping, let see some examples:
yo @wptools/plugin:metabox MyMetabox
Create a new metabox called "MyMetabox", the subgenerator take one argument which, in this case, is the class name of the metabox. You can use any name you want but it will fored to be capitalized CamelCase suffixed by "Metabox" or more generic, the subgenerator name, for generated class names, in order to follow common coding standards.
You have also other subgenerators, once it starts it will ask you some questions, based on the subgenerator context in order to customize the class and element rendering.
yo @wptools/plugin:shortcode MyShortcode
yo @wptools/plugin:widget MyWidget
The generator will also take care to update your plugin main class automatically to include the newly generated classes.
- plugin The main generator that create the plugin
- commentspage Subgenerator for creating comments pages
- dashboardpage Subgenerator for creating submenu dashboard pages
- dashwidget Subgenerator for creating dashboard widgets
- linkspage Subgenerator for creating links pages
- managementpage Subgenerator for creating management pages
- mediapage Subgenerator for creating media pages
- menupage Subgenerator for creating menu pages
- metabox Subgenerator for creating metaboxes
- optionspage Subgenerator for creating options pages
- pagespage Subgenerator for creating page pages
- pluginspage Subgenerator for creating plugins pages
- postspage Subgenerator for creating posts pages
- shortcode Subgenerator for creating shortcodes
- submenupage Subgenerator for creating submenu pages
- taxonomy Subgenerator for creating custom taxonomies
- themepage Subgenerator for creating theme pages
- toolbar Subgenerator for creating dashboard toolbars
- userspage Subgenerator for creating users pages
- widget Subgenerator for creating widgets
This is the default generator, once is called it will ask few questions and setup a working project for your WordPress Plugin. Depending on your answers the command can generate a grunt/gulp based project with sass, linters and a lot of features.
- projectName: The unique name slug you want to use for this project. Default:
<folder-name>
- projectTitle: The title for your WordPress Plugin project. Default:
<Folder Name>
- projectDescription: The description of your project. Default:
This is the <projectTitle> description.
- projectManager: The build system you want to use for the project. Default:
grunt
- projectAuthor: The name of the project author. Default:
<your-name>
- projectLicense: The license under the project is developed and released. Default:
ISC
This command will create a metabox class inside the include/metabox/
, than it will update the $metaboxes property on the main plugin class.
The metabox template is based on WordPress Codex Metabox rules, for more information about the code please refer to it.
This command will create a shortcode class inside the include/shortcode/
, than it will update the $shortcodes property on the main plugin class.
The shortcode template is based on WordPress Codex Shortcode rules, for more information about the code please refer to it.
option | default | description |
---|---|---|
filter | false |
Allow the shortcode attributes to be filtered |
enclosing | false |
Create the shortcode as enclosing tag (enable content) |
This command will create a widget class inside the include/widget/
, than it will update the $widgets property on the main plugin class.
The widget template is based on WordPress Codex Widget rules, for more information about the code please refer to it.
- description: The description for the widget. Default:
The [name] widget description.
This command makes very simple to add new widgets to the administration dashboard. Once is run it will create a dashwidget class inside the include/dashwidget/
, than it will update the $dashwidgets property on the main plugin class.
The dashwidget template is based on WordPress Codex Dashboard Widgets rules, for more information about the code please refer to it.
The Toolbar is an area of the screen just above the site that lists useful admininstration screen links such as add a new post or edit your profile. The Toolbar contains links to information about WordPress, as well as quick-links to create new posts, pages and links, add new users, review comments, and alerts to available updates to plugins and themes on your site.
This command will create a toolbar class inside the include/toolbar/
, than it will update the $toolbars property on the main plugin class.
The toolbar template is based on WordPress Codex Toolbar rules, for more information about the code please refer to it.
- title: The title of the toolbar, that will be shown in the bar. Default:
[name] Toolbar
- hasChild: A boolean that decide if the toolbar is enabled for submenus. Default:
true
- childNumber: How many empty child submenu to create, only if hasChild is enabled. Default:
1
Until the module it's not yet available as a global npm module. A global module may be created and symlinked to a local one, using npm.
Move inside the project folder and type:
npm link
That will install your project dependencies and symlink a global module to your local file. After npm is done, you'll be able to call yo @wptools/plugin
- Create an issue and describe your idea
- Fork the project (https://github.com/codekraft-studio/generator-wordpress-plugin/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Publish the branch (
git push origin my-new-feature
) - Create a new Pull Request
Apache-2.0 © codekraft-studio
- Yeoman has a heart of gold.
- Yeoman is a person with feelings and opinions, but is very easy to work with.
- Yeoman can be too opinionated at times but is easily convinced not to be.
- Feel free to learn more about Yeoman.