WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 11 months 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.

Related ticket #10441 and changeset [37861]

Attachments (1)

44406.diff (700 bytes) - added by naoki0h 11 months ago.

Download all attachments as: .zip

Change History (2)

@naoki0h
11 months ago

#1 @naoki0h
11 months ago

I think ! empty( $replacement ) is better. Because it adjust false and null.

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 argument false, it affects do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message ) .

Note: See TracTickets for help on using tickets.