[wp-trac] [WordPress Trac] #46635: Improve identifying of non–trivial callbacks in hooks

WordPress Trac noreply at wordpress.org
Thu Jul 25 08:12:07 UTC 2024


#46635: Improve identifying of non–trivial callbacks in hooks
--------------------------------------+-------------------------------
 Reporter:  Rarst                     |       Owner:  (none)
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  coding-standards
--------------------------------------+-------------------------------

Comment (by joehoyle):

 Hoping to bring this back to life, as I think we need a solution to be
 able to use PHP 8.1 first class callables in WordPress with a way to
 remove them.

 I think there are two proposals in this PR that are most interesting:

 1. from @schlessera, the proposal is to introduce a `RemovableClosure`
 class which takes a unique ID and a the callable. Only a very small change
 is needed to the Filter/Actions internals to pull the unique ID.

 2. from @gmazzap (github), the proposal is to add an optional 4th argument
 to add_action/add_filter with a unique id, which is used in-place of the
 callable ID. This is probably the most ergonomic, but requires more
 changes to the Filter/Actions API and internals.

 I personally prefer the first proposal from @schlessera as I think it will
 be simpler to introduce and won't expand the Filters API. The only thing I
 might suggest there would be to use an interface `Identifiable_Callback`
 or similar which just exposes the `get_id(): string` function. This means
 3rd parties can implement their own versions of `RemovableClosure ` should
 they want.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46635#comment:29>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list