Skip to content

Base WP Plugin is a starter WordPress plugin to use as a base to build WordPress plugins from scratch. Contains my preferred configuration files for handling the assets files like JavaScript, CSS, and images using Webpack and also handles WordPress Coding Standards through Composer.

License

Notifications You must be signed in to change notification settings

sarahcssiqueira/base-wp-plugin

Repository files navigation

Base WP Plugin

Project Status: Active – The project has reached a stable, usable state and is being actively developed. License: GPL v2 PluginTerritory Release Version

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:

Usage

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.

Install Setup Packages

  • npm install && composer install

Development

Start Development Server

  • npm run dev

Run PHPCS

  • composer cs
  • composer cbf

Build

To optimize and minify assets to the build folder with wepback run:

  • npm run build

PHP Classes

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,
		];
	}

About

Base WP Plugin is a starter WordPress plugin to use as a base to build WordPress plugins from scratch. Contains my preferred configuration files for handling the assets files like JavaScript, CSS, and images using Webpack and also handles WordPress Coding Standards through Composer.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published