[wp-trac] [WordPress Trac] #44831: apply_filters_deprecated() and do_action_deprecated() should only trigger a notice when a callback is hooked
WordPress Trac
noreply at wordpress.org
Wed Aug 22 15:16:30 UTC 2018
#44831: apply_filters_deprecated() and do_action_deprecated() should only trigger a
notice when a callback is hooked
--------------------------+-------------------------------------
Reporter: johnbillion | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: 4.6
Severity: normal | Keywords: needs-patch 2nd-opinion
Focuses: docs |
--------------------------+-------------------------------------
The inline docs for `apply_filters_deprecated()` includes the following
example code:
{{{
// Old filter.
return apply_filters( 'wpdocs_filter', $value, $extra_arg );
// Deprecated.
return apply_filters_deprecated( 'wpdocs_filter', array( $value,
$extra_arg ), '4.9', 'wpdocs_new_filter' );
}}}
The problem with this code is that the deprecated notice is triggered
regardless of whether a callback is hooked into the deprecated filter or
not. The deprecated notice should only be triggered if a callback is
hooked into the filter.
Two options to fix this. Either:
1. Update the example code to include a check for
`has_filter()`/`has_action()`, or
2. Add a check for `has_filter()`/`has_action()` inside
`apply_filters_deprecated()`/`do_action_deprecated()` so the notice is
only triggered when a callback is hooked.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44831>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list