Skip to content
Snippets Groups Projects
Verified Commit daaa2c13 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

docs: improve documentation

parent e7302553
No related branches found
No related tags found
2 merge requests!21.x,!1Draft: Basic implementation of plugin initializer
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
......@@ -41,7 +41,13 @@ most of the time you will need a few more steps to make the most of plugin initi
#### Using dependency injection container
Paired with `php-di/php-di`, you are able to take leverage of dependency injection in your
WordPress plugin.
WordPress plugin. `wp-init` is ready to pick up all of your hook provider classes from special
container entry named `hooks`. Any class registered in this array will be called during
`plugins_loaded` hook.
```shell
composer require php-di/php-di
```
```php
<?php
......@@ -54,7 +60,11 @@ use WPDesk\Init\PluginInit;
require __DIR__ . '/vendor/autoload.php';
$plugin = (new PluginInit())
->add_container_definitions(__DIR__ . '/config/services.inc.php')
->add_container_definitions([
'hooks' => [
\DI\autowire( \Example\PostType\BookPostType::class )
]
])
->init();
```
......
......@@ -24,6 +24,14 @@ final class PluginInit {
/** @var string|null Plugin identifier. */
private $slug;
/**
* Define environment constraints required by a plugin. If requirements are not fulfilled,
* the plugin will not be able to instantiate.
*
* Validation rules are defined according to `wp-basic-requirements` documentation.
*
* @see https://gitlab.wpdesk.dev/wpdesk/wp-basic-requirements
*/
public function set_requirements( array $requirements ): self {
$this->requirements = $requirements;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment