PHPackages                             fluid22/modules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. fluid22/modules

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

fluid22/modules
===============

Module system for developing plugins in WordPress

2.0.0(2mo ago)047MITPHPPHP ^7.4 || ^8.0CI passing

Since Oct 10Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/fluid22/modules)[ Packagist](https://packagist.org/packages/fluid22/modules)[ Docs](https://github.com/fluid22/modules)[ RSS](/packages/fluid22-modules/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (2)Versions (5)Used By (0)

fluid22/modules
===============

[](#fluid22modules)

Small helpers for structuring WordPress plugins as **modules**: a shared [League Container](https://github.com/thephpleague/container) instance, an abstract `Module` base class (hooks + templates), and an optional `Options` model around `get_option` / `update_option`.

**Package:** [`fluid22/modules` on Packagist](https://packagist.org/packages/fluid22/modules)
**Source:** [github.com/fluid22/modules](https://github.com/fluid22/modules)

Requirements
------------

[](#requirements)

- PHP **^7.4 || ^8.0**
- WordPress (uses `apply_filters`, `get_option`, `update_option`, `delete_option`)
- Composer

Installation
------------

[](#installation)

```
composer require fluid22/modules
```

Autoloading loads `Fluid22\Module\` from `src/` and **always** includes `src/helpers.php`, which defines the global `container()` / `start()` API in the `Fluid22\Module` namespace.

Quick start
-----------

[](#quick-start)

### 1. Bootstrap the container and modules

[](#1-bootstrap-the-container-and-modules)

Early in your plugin (for example in the main plugin file after Composer’s autoloader):

```
use function Fluid22\Module\start;

start( [
    \MyPlugin\Modules\Assets::class,
    \MyPlugin\Modules\Admin::class,
], 'my-plugin' );
```

`start()` registers each class with the container identified by the given key, resolves instances in order, and calls `setup()` on every instance that extends `Fluid22\Module\Module`.

**Multiple plugins on one site:** always pass a stable, plugin-specific key (your text domain works well) as the second argument to `start()` and `container()`. Each key gets its own isolated container, so bindings, the autowire setting, and resolved modules never collide across plugins. Omitting the key uses a shared `'default'` bucket — fine for a single consumer, unsafe if other plugins might also use this library.

After all modules have booted, the library fires:

```
do_action( 'fluid22_modules_booted', string $key, array $modules );
```

Use this to sequence cross-plugin wiring.

### 2. Define a module

[](#2-define-a-module)

Place each module in its own directory and extend `Module`. Implement `setup()` to register actions, filters, shortcodes, and so on.

```
