#54440 closed defect (bug) (fixed)
Make remove_filter param type more inclusive
Reported by: | malthert | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 5.9 | Priority: | normal |
Severity: | normal | Version: | 2.2 |
Component: | Plugins | Keywords: | has-patch |
Focuses: | docs | Cc: |
Description
remove_filter/remove_action $callback type can be string/array too, not just callable, which is why it makes sense to make it more inclusive.
(e.g. if theme/plugin has code to remove_action for a function/action that might not exist, it would make no sense if we would have to check if it's callable before calling remove_action on it, since this logic is already there in remove_action)
Change History (10)
This ticket was mentioned in PR #1881 on WordPress/wordpress-develop by kkmuffme.
3 years ago
#1
#3
follow-up:
↓ 5
@
3 years ago
- Version changed from trunk to 2.2
Hi there, thanks for the PR!
It looks like this was introduced in [5142] / #3852 for WordPress 2.2 and adjusted in [34566] / #34032. Setting the version accordingly.
Just noting that there are currently 77 instances of @param callable
in 22 files in core, so changing it just for these two functions seems inconsistent.
I think, while callable
can technically be represented as a string or an array, it's not quite the same, as it's not just any string or array but specifically a callable function. So I think the current documentation makes sense, and changing it to callable|string|array
could cause more confusion.
#4
@
3 years ago
- Keywords 2nd-opinion added
I understand the concern is that the string or array passed to this function does not have to be a valid callable, hence the suggestion to change the docblock to callable|string|array
.
For example:
remove_action( 'foo', 'this_function_may_or_may_not_exist' );
The above is valid use of this function even though the $callback
parameter is not a callable
.
#5
in reply to:
↑ 3
@
3 years ago
As John correctly says: for remove_filter the "callable" does not actually have to be callable. A string/array is fine (e.g. if your theme sets remove_action for a plugin that is not activated, the callback is NOT actually callable, but the code is still valid and runs without error)
For all other instances (e.g. add_action) it has to be callable, otherwise you will get a PHP error when it runs.
#6
@
3 years ago
- Keywords 2nd-opinion removed
- Milestone changed from Awaiting Review to 5.9
- Owner set to johnbillion
- Status changed from new to reviewing
#7
@
3 years ago
I pushed some additions to the PR. The following functions (and their WP_Hook
counterpart methods) all accept a callback that doesn't have to be a valid callable:
remove_filter()
has_filter()
remove_action()
has_action()
_wp_filter_build_unique_id()
Trac ticket: https://core.trac.wordpress.org/ticket/54440