All features

Cherry Blossom feature

Framework Traits: Module Replacements trait

Registers module replacements owned by a bootstrap or coordinator.

Registers module replacements owned by a bootstrap or coordinator.

Capabilities and extension points

Provides explicit, non-instantiating registration before dependent modules load.

WP_Module includes this helper. Fixed Main bootstraps opt in and override get_module_replacement_scope() with null to allow mappings across the theme.

Registers canonical-module => implementation-class mappings.

Call at the beginning of init(), before parent::init() or load_modules(). Classes are autoloaded for validation; instances are never requested here. Each entry is independent: invalid entries emit a diagnostic and return false without preventing valid entries from registering. An invalid list emits a diagnostic and returns an empty result.

  • param array<string, string> $replacements Canonical class names mapped to extending implementations.
  • return array<string|int, bool> Registration results keyed by the supplied mapping key.

Restricts a coordinator to its canonical namespace descendants.

Inherited replacements retain the trait owner's scope, not the child implementation namespace. Main bootstraps override this with null. This is an ownership convention, not an authorization boundary for PHP.

  • return string|null Canonical namespace prefix, or null for unrestricted Main registration.

Source reference

This editable reference page is based on the PHP documentation in framework/traits/trait-module-replacements.php.