Skip to content

Empower your WordPress plugin development with our starter pack, featuring Gulp pre-configured for effortlessly creating a custom WordPress Plugin Boilerplate in under a minute.

License

vijayhardaha/wordpress-plugin-boilerplate

Repository files navigation

WordPress Plugin Boilerplate

Empower your WordPress plugin development with our starter pack, comes pre-configured with Gulp, designed to help you set up a custom WordPress Plugin boilerplate in minutes.

Getting Started

To get started, follow these simple steps:

  1. Clone this GitHub repository into your WordPress plugins directory.
  2. In the plugin directory, run the following command: pnpm i && composer install

After completing these initial steps, let's dive into setting up your plugin for success:

  • Automated Setup: Execute pnpm run setup to launch the automated setup process.
  • Plugin Name: Input your desired plugin name when prompted, such as "WP Mail Checker" or "Bulk Email Sender."
  • Seamless Configuration: Our script will intelligently update the plugin name and related keywords throughout your plugin files. Look for the "Complete!" message upon successful completion, or troubleshooting messages if needed.

Development and Building

Simplify your development workflow with these commands:

  • Watch for Changes: Use pnpm run dev to automatically compile your files whenever changes are made.
  • Build for Release: When ready, run pnpm run build to compile your files for release.

Linting and Code Fixing

Maintain code quality effortlessly with a suite of 8 scripts:

  • lint:css for SCSS file linting.
  • lint:js for JavaScript file linting.
  • lint:php for PHP file linting.
  • lint to check CSS, JavaScript, and PHP files together.
  • lint-fix:css to automatically fix SCSS files.
  • lint-fix:js for automatic JavaScript file fixes.
  • lint-fix:php to correct PHP file issues.
  • lint-fix to tackle CSS, JavaScript, and PHP issues together.

Generate POT (Languages) File

  1. Install WP-CLI: Follow the official guide and add it to your PATH.
  2. Create POT File: Execute pnpm run makepot to generate a POT file for languages.

Key Insights

To provide clarity, here are the essential keywords in use:

Keyword Usage
custom-plugin Used as a prefix or postfix in various files.
custom-plugin Serves as the plugin's text domain and assets enqueue handle prefix.
Custom Plugin Represents the plugin's name across all plugin files.
Custom_Plugin Used as the final class name and class name prefix.
custom_plugin Used as the main function name and functions name prefix.
CUSTOM_PLUGIN Used as a prefix for constants.

What's Happening Behind the Scenes?

When configuring your plugin using the Plugin Boilerplate, the Key Insights mentioned earlier serve as placeholders. These placeholders are dynamically replaced with the plugin name you provide during setup.

Running pnpm run setup is a one-time command that initiates this process. Upon successful completion, it performs several important actions:

  1. Cleanup: It removes setup.mjs, .git, and README.md files/directories, ensuring a clean start for your project.
  2. Script Removal: The setup script itself is deleted from your package.json to prevent unintended reconfiguration.
  3. Dependency Optimization: Dependencies that were specific to the setup process are removed, leaving only the essential dependencies needed for your plugin development.

This streamlined setup process ensures your plugin starts on the right foot, eliminating unnecessary clutter and dependencies while setting the stage for efficient development.

Plugin Structure

Your WordPress plugin is organized as follows:

  • custom-plugin.php: The main plugin file contains essential information, initializes constants, and provides a global function to access the primary class instance.

  • gulpfile.mjs: This file houses Gulp tasks responsible for automating various aspects of your plugin development, such as CSS preprocessing, JavaScript bundling, and asset optimization.

  • includes: Within this directory, you'll find PHP files, organized into classes and function files. Class files start with a class- prefix, while function files end with a -functions.php postfix. The admin subdirectory contains backend-related files.

  • src: The src directory houses source files for your plugin's assets, such as raw CSS, JavaScript, images, and fonts. You can make modifications to these source files during development.

  • assets: In this directory, you'll find the compiled and optimized assets, including minified CSS and JavaScript files, as well as optimized images and fonts. These build assets are automatically generated by the Gulp tasks configured in the gulpfile.mjs. Please avoid manual modifications in this directory, as these files are regenerated during the build process.

This structured approach ensures your plugin remains organized, maintainable, and efficient throughout its development lifecycle.

License

Copyright (C) 2021-2023, Vijay Hardaha. WordPress Plugin Boilerplate is distributed under the terms of the GNU GPL.

Contributions

We welcome contributions from the WordPress community to make this starter pack even better!


Made with ❤ by Vijay Hardaha