WordPress Developer
Read post

Rethinking do_action(): Events as objects, hooks as class names

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.

    #architecture#php#wordpress#react-hooks
Aug 03•13m read time•From developer.wordpress.org
Post cover image
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 early
5.7K Impressions
WordPress Developer's image
WordPress Developer

WordPress Dev's resource offers insights, tutorials, and resources for WordPress developers and webs...

291 Followers

•

506 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard