Back to Portfolio

Quick Start

Install

bash

1 2 3 4 5 6 7 # move into the plugin directory $ cd wp-content/plugins # clone the starter kit repository $ git clone https://github.com/yourvendor/wordpress-plugin-starter-kit.git $ cd wordpress-plugin-starter-kit # install composer dependencies $ composer install

For published plugins, change it to a unique vendor namespace to avoid class name collisions with other plugins.

Plugin entry file

the plugin entry file is where the plugin is initialized and the service provider is registered.

sefra-starter.php

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?php /** * Plugin Name: Sefra Plugin Starter * Description: A starter plugin for WordPress developers. * Version: 1.0.0 * * @package plugin-starter */ // Prevent direct access if( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } use AppProvidersPluginServiceProvider; use SefraContainer; use SefraProvidersApp; use AppPlugin; require_once __DIR__ . '/vendor/autoload.php'; App::registerProviders($providers = [ PluginServiceProvider::class, ]); Container::getInstance()->resolve(Plugin::class)->boot();

the App::registerProviders method registers the service providers for the plugin, and the Container::getInstance()->resolve(Plugin::class)->boot(); line resolves and boots the main plugin class.

Activate the plugin.

If no errors appear, the starter kit is correctly installed.

Create a Service Provider

A service provider is responsible for registering bindings and bootstrapping services for the plugin. Create a service provider by implementing the Sefra\Providers\ServiceProvider interface and then included in the $providers array passed to App::registerProviders method.

The starter kit already includes a default PluginServiceProvider at src/Providers/PluginServiceProvider.php. You only need to edit it and register your services.

Next Steps

To get started with the WordPress Plugin Starter Kit, consider exploring the following topics:

All these topics are covered in the Features section.