fasteddys / 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)

Home Page:http://vojay.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WordPress plugin development boilerplate

Logo

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.

Plugin example

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.

Workflow settings

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.

Start WordPress

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

Your plugin is already installed automatically and can be activated!

Plugin example

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.

Build plugin

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.

Release plugin

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:

Shortcode example 1 Shortcode example 2

Gutenberg block:

Gutenberg example

Admin page:

Admin example

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!

About

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

http://vojay.de/

License:Apache License 2.0


Languages

Language:PHP 42.4%Language:Shell 25.7%Language:JavaScript 18.6%Language:Makefile 9.9%Language:Dockerfile 3.4%