wpdesk / wp-init
Bootstrap for a WordPress plugin
Requires
- php: >=7.4 | ^8
- php-di/php-di: ^6 || ^7
- psr/container: ^1 || ^2
Requires (Dev)
- brain/monkey: ^2.6
- phpunit/phpunit: ^8 || ^9
- symfony/filesystem: ^5.4 || ^6.2
- wpdesk/phpstan-rules: ^1.1
- wpdesk/wp-basic-requirements: ^3
- wpdesk/wp-builder: ^2.0
- wpdesk/wp-code-sniffer: ^1.3
- wpdesk/wp-wpdesk-license: ^4
Suggests
- wpdesk/wp-basic-requirements: Enables your plugin to check an environment requirement before instantiation, e.g. PHP version or active plugins
- wpdesk/wp-logs: PSR-3 compatible logger with WooCommerce handler.
Conflicts
- wpdesk/wp-basic-requirements: <3 >=4
- wpdesk/wp-logs: <1.13 >=2
- wpdesk/wp-wpdesk-license: <4 >=5
README
Boot your plugin with superpowers.
Installation
To use this library in your project, add it to composer.json
:
composer require wpdesk/wp-init
Creating a Plugin
Preferred method of using this library exercise Object Oriented Programming and organizing your actions and filters in a multiple classes, although it isn't the only way you can interact (and benefit from this library).
The plugin initialization consists of the following steps:
- Create a regular main plugin file, following header requirements
- Prepare DI container definitions for your services.
- Declare all classes included in hook binding.
The above limits your main plugin file to a short and simple structure.
<?php
/**
* Plugin Name: Example Plugin
*/
use WPDesk\Init\Init;
require __DIR__ . '/vendor/autoload.php';
Init::setup('config.php')->boot();
Plugin configuration
For plugin configuration, you may focus on succinct, declarative configuration.
<?php
return [
'hook_resources_path' => 'config/hook_providers',
'services' => 'config/services.inc.php',
'cache_path' => 'generated',
'requirements' => [
'plugins' => [
'name' => 'woocommerce/woocommerce.php',
'nice_name' => 'WooCommerce',
]
],
'plugin_class_name' => 'Example\Plugin',
];
Usage with wpdesk/wp-builder
As a legacy support, it is possible to power up your existing codebase, which uses
wpdesk/wp-builder
with this library capabilities, as autowired services.
The only change, you have to do (besides configuration of services) is adding hookables as class string, ready for handling by DI container:
- $this->add_hookable( new \WPDesk\Init\Provider\I18n() );
+ $this->add_hookable( \WPDesk\Init\Provider\I18n::class );
Credits
This package is heavily inspired by Cedaro's wp-plugin
and Alain Schlesser's basic-scaffold
.
License
Copyright (c) 2024 WPDesk
This library is licensed under MIT.