Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years 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:
Priority: normal Milestone:
Component: Plugins Version: 4.6
Severity: normal Keywords:
Cc: Focuses: docs

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
8 years ago

  • Milestone Awaiting Review
  • Resolutioninvalid
  • Status newclosed

#2 in reply to: ↑ description @SergeyBiryukov
8 years 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.