Opened 6 years ago
Last modified 6 years ago
#44406 new defect (bug)
Mismatch in the default value of the optional replacement argument in do_action_deprecated(), apply_filters_deprecated() and _deprecated_hook()
Reported by: | birgire | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
There's a mismatch in the default value of the optional replacement argument in the functions do_action_deprecated()
, apply_filters_deprecated()
and _deprecated_hook()
.
We have:
function do_action_deprecated( ..., $replacement = false, ... ) { ... } function apply_filters_deprecated( ..., $replacement = false, ... ) { ... }
but then on the other hand:
function _deprecated_hook( ..., $replacement = null, ... ) { ... }
containing a ! is_null( $replacement )
check.
How to fix:
I think adjusting the private function _deprecated_hook()
, could be a safer route, as it's not supposed to be used by plugins or themes. Either adjust the optional input value to false
, or e.g. replace ! is_null( $replacement )
with ! $replacement
to handle both.
How to replicate - Example:
add_action( 'init', function() { add_action( 'foo_action', 'foo_action_callback' ); do_action_deprecated( 'foo_action', array( '123' ), '4.9' ); remove_action( 'foo_action', 'foo_action_callback' ); } ); function foo_action_callback( $var ) { }
Actual message:
foo_action is deprecated since version 4.9! Use instead.
Expected message:
foo_action is deprecated since version 4.9 with no alternative available.
Attachments (1)
Note: See
TracTickets for help on using
tickets.
I think
! empty( $replacement )
is better. Because it adjustfalse
andnull
.Also, I think
null
is better for the default argument of the functions.Because , setting default argument
null
doesn't affect any functions, but if we set default argumentfalse
, it affectsdo_action( 'deprecated_hook_run', $hook, $replacement, $version, $message )
.