Download the PHP package fluid22/modules without Composer
On this page you can find all versions of the php package fluid22/modules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fluid22/modules
More information about fluid22/modules
Files in fluid22/modules
Package modules
Short Description Module system for developing plugins in WordPress
License MIT
Homepage https://github.com/fluid22/modules
Informations about the package modules
fluid22/modules
Small helpers for structuring WordPress plugins as modules: a shared League Container instance, an abstract Module base class (hooks + templates), and an optional Options model around get_option / update_option.
Package: fluid22/modules on Packagist
Source: github.com/fluid22/modules
Requirements
- PHP ^7.4 || ^8.0
- WordPress (uses
apply_filters,get_option,update_option,delete_option) - Composer
Installation
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
1. Bootstrap the container and modules
Early in your plugin (for example in the main plugin file after Composer’s autoloader):
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:
Use this to sequence cross-plugin wiring.
2. Define a module
Place each module in its own directory and extend Module. Implement setup() to register actions, filters, shortcodes, and so on.
The module’s directory is derived from the concrete class file path (get_dir()), so colocate templates/ next to that class.
3. Templates
Put PHP templates under {ModuleDirectory}/templates/, named {name}.html.php. Subfolders are allowed using / in the template name (for example emails/summary → templates/emails/summary.html.php).
Allowed name characters: letters, digits, _, -, and / between segments. The loader resolves paths with realpath() so files cannot escape templates/.
get_template() returns false if the name is invalid or the file is missing.
Variables are passed as an array; valid PHP variable names are extract()ed into the template with EXTR_SKIP, inside a narrow scope so they cannot clobber internal state. $this in the template is the module instance. Invalid array keys (numeric keys, bad identifiers) are ignored.
4. Dependency injection
container( string $key = null ) returns the League\Container\Container for that key, creating it on first access. By default, setup_container() delegates to League\Container\ReflectionContainer so constructors can type-hint dependencies when autowiring is enabled.
Disable autowiring (per-key via the filter’s second argument):
Register bindings before start() against the same key:
Containers are stored in $GLOBALS['fluid22_containers'] keyed by the container key. For back-compat, the default bucket is also mirrored to $GLOBALS['fluid22_container'].
Options model
Fluid22\Module\Models\Options is a thin, lazy wrapper over WordPress options with a required key prefix.
- Reads load from the database on first access via magic
__get. - Assignments mark keys dirty until
save()callsupdate_option. remove()/__unset()queuedelete_optionon the nextsave().- Constructor:
new Options( ?string $prefix, ?bool $autoload ). A non-empty prefix is required — pass it to the constructor, or defineprotected string $prefix = '…';in a subclass and passnull. Constructing without an effective prefix throwsInvalidArgumentExceptionso plugins can’t accidentally share the same option keys. - The
$autoloadflag is passed as the third argument toupdate_option()(defaultfalse).
Packagist updates
This repository includes a GitHub Actions workflow that calls Packagist’s update-package API when you push to master/main or push tags. Configure PACKAGIST_USER and PACKAGIST_TOKEN in the repo’s Actions secrets, or use Packagist’s built-in GitHub integration instead.
License
MIT. See composer.json for author metadata.