A standardized, organized, object-oriented foundation for building high-quality WordPress Plugins.
The WordPress Plugin Boilerplate includes the following files:
.gitignore
. Used to exclude certain files from the repository.CHANGELOG.md
. The list of changes to the core project.README.md
. The file that you’re currently reading.- A
plugin-name
directory that contains the source code - a fully executable WordPress plugin.
- The Boilerplate is based on the Plugin API, and Documentation Standards.
- All classes, functions, and variables are documented so that you know what you need to change.
- The Boilerplate uses a strict file organization scheme that similar to the WordPress Plugin Repository structure, and that makes it easy to organize the files that compose the plugin.
- The project includes a
.pot
file as a starting point for internationalization. - Contatains templates for:
- Admin menu
- Settings
- Shortcode as a Form and how to pass data from a Javascript and return data back.
- Multisite support
- Network Settings
The Boilerplate can be installed directly into your plugins folder "as-is". You will want to rename it and the classes inside of it to fit your needs. For example, if your plugin is named 'example-me' then:
- rename files from
plugin-name
toexample-me
- change
plugin_name
toexample_me
- change
plugin-name
toexample-me
- change
Plugin_Name
toExample_Me
- change
PLUGIN_NAME_
toEXAMPLE_ME_
- change
PluginName
toExampleMe
- change
Plugin Name
toExample Me
It's safe to activate the plugin at this point.
The WordPress Plugin Boilerplate uses a variable to store the text domain used when internationalizing strings throughout the Boilerplate. To take advantage of this method, there are tools that are recommended for providing correct, translatable files:
Any of the above tools should provide you with the proper tooling to internationalize the plugin.
The WordPress Plugin Boilerplate is licensed under the GPL v2 or later; however, if you opt to use third-party code that is not compatible with v2, then you may need to switch to using code that is GPL v3 compatible.
For reference, here's a discussion that covers the Apache 2.0 License used by Bootstrap.
Note that if you include your own classes, or third-party libraries, there are three locations in which said files may go:
plugin-name/Includes
is where functionality shared between the admin area and the public-facing parts of the site resideplugin-name/Admin
is for all admin-specific functionalityplugin-name/Frontend
is for all public-facing functionality
The plugin is multisite ready out of the box. Highly recommended articles:
The previous version of the WordPress Plugin Boilerplate included support for a number of different projects such as the GitHub Updater.
These tools are not part of the core of this Boilerplate, as I see them as being additions, forks, or other contributions to the Boilerplate.
The same is true of using tools like Grunt, Composer, etc. These are all fantastic tools, but not everyone uses them. In order to keep the core Boilerplate as light as possible, these features have been removed and will be introduced in other editions, and will be listed and maintained on the project homepage.
- Every functions MUST declare parameter type and return type.
- Every class properties MUST be typed.
- Every PHP files MUST have strict type mode enabled by starting with
declare(strict_types=1);
. - Every PHP files MUST contain
if (!defined('ABSPATH')) exit;
right after thenamespace
declaration.
Classes: UpperCamelCase
Functions: camelCase
. You must not omit public
, protected
, or private
modifiers.
Variables: camelCase
Constants: ALL_UPPER_CASE_WITH_UNDERSCORE_SEPARATOR
Parentheses: Allman
Comparison: You should use strict comparison (===
, !==
) whenever possible.
Whitespaces: You must not add a whitespace before and after braces.
<?php
declare(strict_types=1);
namespace PluginName;
if (!defined('ABSPATH')) exit;
class User
{
const DATE_REGISTERED = '2012-06-01';
private int $id;
public function updateAddress($id, $newAddress)
{
// Do something
}
}
The plugin is based on the WordPress Plugin Boilerplate.