All features

Cherry Blossom feature

Framework Traits: WP Module trait

Provides a replaceable WordPress module singleton.

Provides a replaceable WordPress module singleton.

Capabilities and extension points

Provides a replaceable WordPress module singleton.

The class using this trait remains the canonical module. Its concrete implementation can be replaced with an extending class before the module is first instantiated.

Holds the canonical module instance.

  • var object|null

Holds the resolved module class.

  • var string|null

Holds the explicitly registered implementation before resolution.

  • var string|null

Prevents registration while resolution filters are running.

  • var bool

Registers an implementation without resolving or constructing the module.

Prefer register_module_replacements() from Main or a coordinating module. This low-level operation accepts the same implementations as the existing resolver: a public or protected constructor must accept zero arguments. The first explicit registration wins; repeating it before resolution succeeds, while conflicting or late registrations are rejected. Existing module/classes and module/class filters still run at resolution and can override this default. Invalid filtered values retain the existing diagnostic and canonical fallback behavior.

  • param string $implementation Autoloadable extension of the canonical class.
  • return bool Whether registration was accepted.

Loads configured child modules.

Coordinating modules control when this method runs from init(). Pass an explicit list for specialized groups, or omit it to use get_modules().

  • param array|string|null $modules Module class names, or null for the configured list.
  • return array Loaded module instances keyed by class name.

Gets child modules loaded by load_modules().

Coordinating modules override this method; leaf modules inherit an empty list and do not need to define it.

  • return array Module class names.

Returns the canonical module instance.

  • return object Module instance.

Returns the resolved concrete module class.

The first resolution is retained for the remainder of the request. Filters added after this method runs cannot replace a live module.

  • return string Concrete module class.

Determines whether a concrete module class is valid.

  • param mixed $module_class Proposed concrete module class.
  • param string $base_class Canonical module class.
  • return bool Whether the class can implement the module.

Source reference

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