WordPress.org

Make WordPress Core

Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#44831 closed defect (bug) (invalid)

apply_filters_deprecated() and do_action_deprecated() should only trigger a notice when a callback is hooked

Reported by: johnbillion Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6
Component: Plugins Keywords:
Focuses: docs Cc:

Description

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.

Change History (2)

#1 @johnbillion
20 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

#2 in reply to: ↑ description @SergeyBiryukov
20 months ago

  • Keywords needs-patch 2nd-opinion removed

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.

For reference, re-reading [37861], it looks like that's already the case.

Note: See TracTickets for help on using tickets.