#23265 closed enhancement (fixed)
Canonical callback representation
Reported by: | scribu | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Plugins | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
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)
#3
follow-up:
↓ 7
@
12 years ago
- Cc info@… added
Another variant:
add_filter( 'the_content', ['Class_Name', 'static_callback_method'] );
But that should be equal to your first example.
#4
@
12 years 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');
#5
@
12 years 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.
#6
@
12 years 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
#7
in reply to:
↑ 3
@
12 years 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.
#9
@
12 years ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In 24251:
#11
@
11 years ago
In 1294/tests:
+1.