A technique for improving WordPress action hooks by passing typed event objects instead of loose positional arguments. Using `do_action($event::class, $event)` gives you namespaced hook names via fully-qualified class names, IDE autocomplete and static analysis on payloads, and filter-like mutation through mutable object properties — all without any new dependencies. The approach mirrors the PSR-14 event dispatcher pattern and works with WordPress's existing hook API. The post covers event class design with readonly vs mutable properties, observer vs mutator listener patterns, and the tradeoffs between using class names vs fixed strings as hook identifiers.
Table of contents
The hooks to tolerateThe one-line ideaDispatching an event-based hookListening to an event-based hookWhat the event object bought youAn old idea that WordPress had early5.7K Impressions