Base WP Plugin is a starter WordPress plugin to use as a base to build WordPress plugins from scratch. Contains the configuration files for handling the assets files like Javascript, CSS, and images using Webpack.
It uses Composer to handle WordPress Coding Standards and autoloader. The WordPress hooks (actions and filters) are registered using a custom initialize() method instead to hook them in the __constructor of each class. This initialize method
is automatically called in the Init class (It seems overengineering now, but will be useful as you plugin grows up).
Some topics covered in this project:
- Webpack for managing, compiling, and optimizing the plugin's asset files;
- Eslint;
- Babel;
- SASS;
- Stylelint;
- WordPress Coding Standards;
- PHP Namespaces;
- Autoload;
Clone the repository with git clone https://github.com/sarahcssiqueira/base-wp-plugin
or download the latest release. Place it in the /wp-content/plugins/ folder of your WordPress installation.
npm install && composer install
npm run dev
composer cs
composer cbf
To optimize and minify assets to the build folder with wepback run:
npm run build
Classes are automatically loaded by the Init class with the method register_classes_list:
/**
* Loop through the classes list, initialize them,
* and call the initialize() method if it exists
*/
public static function register_classes_list() {
foreach ( self::classes_list() as $class ) {
$classname = self::instantiate( $class );
if ( method_exists( $classname, 'initialize' ) ) {
$classname->initialize();
}
}
}
To add your new classes, make sure add them to the array present in the method classes_list:
/**
* Store the classes inside an array
*
* @return array Full list of classes
*/
public static function classes_list() {
return [
Plugin::class,
YourNewClass::class,
];
}