#23265 closed enhancement (fixed)
Canonical callback representation
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.6 |
| Component: | Plugins | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | info@… |
Description (last modified by scribu)
Since PHP 5.3, you have various ways of passing the same callback:
add_filter( 'the_content', array( 'My_Plugin_Main_Class', 'the_content' ) ); add_filter( 'the_content', 'My_Plugin_Main_Class::the_content' ); add_filter( 'the_content', '\\My_Plugin_Main_Class::the_content' );
Currently, you have to use the exact same syntax in remove_action(), or it won't work.
It would be nice if _wp_filter_build_unique_id() converted all these variations to a canonical representation.
Sprung out of #23259
Attachments (2)
Change History (13)
comment:3
follow-up:
↓ 7
toscho
— 5 months ago
- Cc info@… added
Another variant:
add_filter( 'the_content', ['Class_Name', 'static_callback_method'] );
But that should be equal to your first example.
comment:4
scribu
— 5 months ago
It seems the string syntax was added even earlier:
// Type 4: Static class method call (As of PHP 5.2.3)
call_user_func('MyClass::myCallbackMethod');
comment:5
scribu
— 5 months ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 3.6
23265.diff fixes the most common case and has 23265.tests.diff to go with it.
comment:6
wonderboymusic
— 5 months ago
I looked at the same-ish thing here #21267
Here was my patch:
https://core.trac.wordpress.org/attachment/ticket/21267/filter-callback-keys.diff
Main problem is closures
comment:7
in reply to:
↑ 3
rmccue
— 5 months ago
Replying to toscho:
Another variant:
add_filter( 'the_content', ['Class_Name', 'static_callback_method'] );But that should be equal to your first example.
Yep, that's just shorthand for an array in 5.4+.
With closures, they're pretty much going to have to be assigned to a variable to do anything with them. The only thing I can think of doing is involving where they were defined via ReflectionFunction, but that seems a little horrible.
comment:9
nacin
— 5 weeks ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In 24251:
comment:10
SergeyBiryukov
— 5 weeks ago
- Milestone changed from Future Release to 3.6
comment:11
nacin
— 33 hours ago
In 1294/tests:
+1.