wp-plugin-boilerplate

WordPress plugin development boilerplate to jumpstart WordPress plugin projects with Docker and Github Actions (includes examples for an admin page, shortcode and Gutenberg block)

APACHE-2.0 License

Stars
33
Committers
1

WordPress plugin development boilerplate

This project is a WordPress plugin development boilerplate to jumpstart WordPress plugin projects. It utilizes Docker for a local environment and includes an automated setup of WordPress with a configurable admin user and password.

With the boilerplate you get a simple template to get started with a plugin, which includes a dedicated admin page, an example shortcode to be rendered on any page as well as a custom Gutenberg block.

Furthermore it includes a build script and Github Workflow to generate an installable plugin release.

Environment:

  • Docker
  • Linux, macOS

Simply create a fork of this repo and get started by implementing your plugin in an efficient environment.

Setup

  • Fork the project
  • Adjust the plugin name in .env
  • Enable access to the GITHUB_TOKEN for the Github workflow to create releases: Repository settings -> Actions -> General -> Workflow permission -> select Read and write permissions.

Commands to interact with Docker as well as building the plugin are encapsulated in the Makefile.

Start local WordPress via Docker

make wp-start

This starts a local WordPress and database container. It uses the latest WordPress version and installs the WordPress CLI to automatically setup an admin user with the configured user and password in .env. After the setup is complete, you will get details on how to access WordPress in the log output.

After starting the Docker setup, you can reach WordPress locally via:

Your plugin is already installed automatically and can be activated!

Stop local WordPress via Docker

make wp-stop

Build plugin

make

This command will trigger the bin/build.sh script with the configured plugin name in .env to create an installable WordPress plugin .zip file.

Also the Github workflow in .github/workflows/build.yml will automatically build the plugin and create a release with the .zip file on any push to main.

Plugin development

The source of your plugin is in src/. There are already examples added, to get started quickly:

  • src/index.php: General setup and global variables / functions
  • src/admin.php: Admin page
  • src/frontend.php: Code to render the custom shortcode
  • src/block.js: Custom Gutenberg block example
  • src/script.js: Custom JS code loaded with your plugin
  • src/style.css: Custom CSS code loaded with your plugin

With the given example, you will get a custom admin page, a shortcode [my-plugin] that will be rendered with a "Hello World!" example as well as a custom Gutenberg block that simply renders a text.

Shortcode:

Gutenberg block:

Admin page:

From here, you can get started with your plugin within an efficient local environment including a build workflow.

If you use this boilerplate, feel free to star ⭐️ this repo and add your project to this README. Knowledge shared is knowledge squared!

Related Projects