WordPress.org

Make WordPress Core

Opened 5 weeks 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]

Change History (0)

Note: See TracTickets for help on using tickets.