Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#49698 closed defect (bug) (fixed)

Issue with replacement for filter deprecation

Reported by: renathoc's profile renathoc Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: 5.4
Component: Plugins Keywords: has-patch
Focuses: Cc:

Description

The function apply_filters_deprecated has the default value for the $replacement argument as false.

This function uses the _deprecated_hook, sending the same $replacement argument. But in the _deprecated_hook, it considers the default as null.

So the problem occurs when we use the apply_filters_deprecated without a replacement, the with no alternative available message is not shown, but Use instead.

Attachments (1)

49698.diff (6.8 KB) - added by jignesh.nakrani 5 years ago.
changed default values for $replacement and $message parameters to string and fixed ! is_null() strict type check

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
5 years ago

  • Component changed from General to Plugins

#2 @SergeyBiryukov
5 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.5
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

Hi there, welcome to WordPress Trac! Thanks for the ticket.

The issue is already fixed for WordPress 5.4 in [46792] / #48817.

That said, I think we should switch the default values for $replacement and $message parameters in these functions to an empty string instead of null, to match the documented type of string. The ! is_null() check for these parameters seems unnecessarily strict, we only need to check for a truthy value.

This would affect:

  • _deprecated_function()
  • _deprecated_constructor()
  • _deprecated_file()
  • _deprecated_argument()
  • _deprecated_hook()
  • apply_filters_deprecated()
  • do_action_deprecated()

#3 @renathoc
5 years ago

Great! Thank you @SergeyBiryukov

@jignesh.nakrani
5 years ago

changed default values for $replacement and $message parameters to string and fixed ! is_null() strict type check

#4 @jignesh.nakrani
5 years ago

  • Keywords has-patch added; needs-patch removed

#5 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 48327:

Plugins: Consistently use an empty string as the default value for $replacement and $message parameters in:

  • _deprecated_function()
  • _deprecated_constructor()
  • _deprecated_file()
  • _deprecated_argument()
  • _deprecated_hook()
  • apply_filters_deprecated()
  • do_action_deprecated()

This matches the documented type of string for these parameters and removes unnecessarily strict ! is_null() checks.

Follow-up to [46792].

Props jignesh.nakrani, renathoc, SergeyBiryukov.
Fixes #49698.

#6 @jrf
4 years ago

Just came across this patch and noticed that the changes in the default value did not get a @since changelog entry while they do need one to inform plugin/themes which use these functions.

Note: See TracTickets for help on using tickets.