This is a skeleton WordPress plugin that can scaffold a WordPress plugin. This
template includes a base plugin file, autoloaded PHP files, unit tests powered
by Mantle, front-end assets compiled via Webpack,
and Continuous Integration via GitHub Actions. Actions are
configured to test the plugin and also build it for releases.
The workflows will also create a *-built branch, too.
The plugin supports front-end assets which can be enqueued inside
src/assets.php or from within an entry points index.php file. For plugins
that don't require front-end assets, the configuration script below will prompt
you to delete the front-end files if you don't wish to use them.
Follow these steps to get started:
- Press the "Use template" button at the top of this repo to create a new repo with the contents of this skeleton.
- Run
make(orphp ./configure.php) to run a script that will replace all placeholders throughout all the files. - Have fun creating your plugin! 🎊
Contributors: author_username
Tags: vendor_name, create-wordpress-plugin
Stable tag: 0.0.0
Requires at least: 6.3
Tested up to: 6.7
Requires PHP: 8.2
License: GPL v2 or later
A skeleton WordPress plugin.
You can install the package via Composer:
composer require alleyinteractive/create-wordpress-pluginActivate the plugin in WordPress and use it like so:
$plugin = Create_WordPress_Plugin\Skeleton\Example_Plugin();
$plugin->perform_magic();To setup a WordPress installation and run the plugin in a local environment, you
can use wp-env via the composer dev command:
npm install
composer devThe command will start a local WordPress environment with the plugin activated
while also running the front-end assets build process. You can also run npm run start to start the front-end assets build process separately. The front-end
assets will be compiled into the build directory and will be enqueued
automatically by the plugin.
The plugin supports registering post and term meta via JSON files located in the
config directory. Out of the box, the plugin will look for
config/post-meta.json for post meta and config/term-meta.json for term meta.
{
"$schema": "https://raw.githubusercontent.com/alleyinteractive/mantle-framework/HEAD/src/mantle/support/schema/meta.json",
"example_meta_key": {
"post_types": "article",
"type": "string"
},
"another_meta_key": {
"post_types": [ "article", "page" ],
"type": "number",
"single": false,
"default": 0
}
}For more information on how to register meta via JSON files, see the documentation.
All directories created in the entries directory can serve as entry points and will be compiled with @wordpress/scripts into the build directory with an accompanied index.asset.php asset map.
To generate a new entry point, run the following command:
npm run create-entryTo generate a new slotfill, run the following command:
npm run create-slotfillThe command will prompt the user through several options for creating an entry or slotfill. The entries are scaffolded with the @alleyinteractive/create-entry script. Run the help command to see all the options:
npx @alleyinteractive/create-entry --helpVisit the package README for more information.
You can also include an index.php file in the entry point directory for enqueueing or registering a script. This file will then be moved to the build directory and will be auto-loaded with the load_scripts() function in the functions.php file. Alternatively, if a script is to be enqueued elsewhere there are helper functions in the src/assets.php file for getting the assets.
Use the create-block command to create custom blocks with @alleyinteractive/create-block script and follow the prompts to generate all the block assets in the blocks/ directory.
Block registration, script creation, etc will be scaffolded from the create-block script. Run npm run build to compile and build the custom block. Blocks are enqueued using the load_scripts() function in src/assets.php.
Update the WordPress dependency packages used in the project to their latest version.
To update @wordpress dependencies to their latest version use the packages-update command:
npx wp-scripts packages-updateThis script provides the following custom options:
--dist-tag– allows specifying a custom dist-tag when updating npm packages. Defaults tolatest. This is especially useful when using@wordpress/dependency-extraction-webpack-plugin. It lets installing the npm dependencies at versions used by the given WordPress major version for local testing, etc. Example:
npx wp-scripts packages-update --dist-tag=wp-WPVERSION`Where WPVERSION is the version of WordPress you are targeting. The version
must include both the major and minor version (e.g., 6.7). For example:
npx wp-scripts packages-update --dist-tag=wp-6.7`Run npm run test to run Jest tests against JavaScript files. Run
npm run test:watch to keep the test runner open and watching for changes.
Run npm run lint to run ESLint against all JavaScript files. Linting will also
happen when running development or production builds.
Run composer test to run tests against PHPUnit and the PHP code in the plugin.
Unit testing code is written in PSR-4 format and can be found in the tests
directory.
The plugin uses
action-release via a
built release workflow to compile and
tag releases. Whenever a new version is detected in the root plugin's headers in
the plugin.php file or in the composer.json file, the workflow will
automatically build the plugin and tag it with a new version. The built tag will
contain all the required front-end assets the plugin may require. This works
well for publishing to WordPress.org or for submodule-ing.
When you are ready to release a new version of the plugin, you can run
npm run release/composer release to start the process of setting up a new
release. If you want to do this manually you can follow these steps:
-
Change the
Versionin theplugin.phpfile to a new higher-level version.- * Version: 0.0.0 + * Version: 0.0.1
✨
npm run releasewill do this for you automatically. -
Commit your changes and push to the repository.
-
Check the actions tab in the repository to see the progress of the release. The action will automatically create a new tag and release for the plugin. You are done!
Please see CHANGELOG for more information on what has changed recently.
This project is actively maintained by Alley Interactive. Like what you see? Come work with us.
The GNU General Public License (GPL) license. Please see License File for more information.