Documentation

WpHookfileLoader extends HookfileLoader
in package

FinalYes

WordPress-specific hookfile discovery.

Hookfiles are PHP scripts loaded at boot to register signal subscriptions, extend services, or otherwise inject behavior into the MIDDAG runtime without packaging a full extension. Three discovery sources, in load order:

  1. WP_CONTENT_DIR/{hookfileName} — site-local override
  2. WP_CONTENT_DIR/themes/{active}/{hookfileName} — active theme
  3. Plugins/themes responding to the {filterName} filter and returning a list of absolute paths.

The file name and the filter name are constructor arguments. Their defaults are the neutral library marker (middaglib_hooks.php, middaglib_hookfiles), which names no product: a consumer passes its own pair.

Source order matters: later sources override earlier ones because the bus reflects last-wins semantics for re-registered keys. Plugin contributions are last so they can patch site/theme.

Table of Contents

Properties

$activeTheme  : string|null
$contentDir  : string|null
$filterName  : string
$hookfileName  : string

Methods

__construct()  : mixed
discoverPaths()  : array<string|int, string>
activeThemeSlug()  : string|null
contentDir()  : string|null
filterContributions()  : array<string|int, string>
maybeAdd()  : void

Properties

$filterName read-only

private string $filterName = 'middaglib_hookfiles'

$hookfileName read-only

private string $hookfileName = 'middaglib_hooks.php'

Methods

__construct()

public __construct([string $filterName = 'middaglib_hookfiles' ][, null|string $contentDir = null ][, null|string $activeTheme = null ][, LoggerInterface $logger = new NullLogger() ][, string $hookfileName = 'middaglib_hooks.php' ]) : mixed
Parameters
$filterName : string = 'middaglib_hookfiles'

WordPress filter consulted for plugin/theme contributions. Filter callbacks receive an array and return an array of absolute paths.

$contentDir : null|string = null

Override WP_CONTENT_DIR. Defaults to the constant when not provided. Tests inject this so they don't depend on a one-shot constant.

$activeTheme : null|string = null

Override get_stylesheet() result. Defaults to the function's return value when null.

$logger : LoggerInterface = new NullLogger()
$hookfileName : string = 'middaglib_hooks.php'

file name looked up in WP_CONTENT_DIR and in the active theme directory

discoverPaths()

protected discoverPaths() : array<string|int, string>
Return values
array<string|int, string> —

absolute, readable hookfile paths

activeThemeSlug()

private activeThemeSlug() : string|null
Return values
string|null

contentDir()

private contentDir() : string|null
Return values
string|null

filterContributions()

private filterContributions() : array<string|int, string>
Return values
array<string|int, string>

maybeAdd()

private maybeAdd(array<string|int, string> &$paths, string $candidate) : void
Parameters
$paths : array<string|int, string>
$candidate : string
On this page

Search results