Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#48817 closed defect (bug) (fixed)

do_action_deprecated and apply_filters_deprecated $replacement param should default to null

Reported by: felipeelia's profile felipeelia Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.4 Priority: normal
Severity: normal Version:
Component: Plugins Keywords: good-first-bug has-patch
Focuses: Cc:

Description

_deprecated_hook, the function responsible for logging an error when an old hook is called, uses is_null to check if a $replacement was provided.

The problem is that $replacement defaults to false (instead of null) on apply_filters_deprecated and do_action_deprecated, displaying the Use %3$s instead.' message without any value.

Attachments (3)

48817.diff (426 bytes) - added by shaampk1 5 years ago.
sprintf function: fixed the missing comma for $replacement var in is_null check.
48817.1.diff (711 bytes) - added by shaampk1 5 years ago.
sprintf function: fixed the missing comma for $version var under ELSE check.
48817.2.diff (1.0 KB) - added by shaampk1 5 years ago.
Reverted previous changes and assigned the default values to both of the functions as NULL

Download all attachments as: .zip

Change History (14)

#1 @felipeelia
5 years ago

  • Keywords good-first-bug added

#2 @felipeelia
5 years ago

  • Keywords needs-patch added

#3 @SergeyBiryukov
5 years ago

  • Component changed from General to Plugins
  • Milestone changed from Awaiting Review to 5.4

#4 in reply to: ↑ description @shaampk1
5 years ago

  • Keywords dev-feedback added

Replying to felipeelia:

_deprecated_hook, the function responsible for logging an error when an old hook is called, uses is_null to check if a $replacement was provided.

The problem is that $replacement defaults to false (instead of null) on apply_filters_deprecated and do_action_deprecated, displaying the Use %3$s instead.' message without any value.

Hi,

This ticket looks interesting. Can you please provide any screenshot or the hook that is causing the issue?

Thanks.

@shaampk1
5 years ago

sprintf function: fixed the missing comma for $replacement var in is_null check.

@shaampk1
5 years ago

sprintf function: fixed the missing comma for $version var under ELSE check.

#5 @shaampk1
5 years ago

  • Keywords has-patch added; needs-patch removed

This ticket was mentioned in Slack in #core by ihtishamzahoor. View the logs.


5 years ago

#7 follow-up: @SergeyBiryukov
5 years ago

Hi @shaampk1, thanks for the patch! However, looks like that's not quite what the ticket meant.

Unlike arrays, sprint() calls don't require the extra comma and in fact will produce a syntax error with that change.

The suggested change is to switch $replacement = false in lines 626 and 653 of wp-includes/plugin.php to $replacement = null, as that is the value being checked in _deprecated_hook() and other related functions, see line 4839 in wp-includes/functions.php.

@shaampk1
5 years ago

Reverted previous changes and assigned the default values to both of the functions as NULL

#8 in reply to: ↑ 7 @shaampk1
5 years ago

Hi, @SergeyBiryukov,

Thanks for the quick assistance. I have just submitted a new patch, could you also please take a quick look. Thanks : )

#9 @felipeelia
5 years ago

  • Keywords dev-feedback removed

Hey @shaampk1! Yes, the last patch addresses what I was trying to highlight :)

I've noticed the problem while hooking a function to the delete_blog action and I guess that that and deleted_blog actions are the only ones that don't provide any replacement.

#10 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 46792:

Plugins: Correct default value of $replacement parameter in do_action_deprecated() and apply_filters_deprecated().

This addresses an inconsistency with _deprecated_hook(), which uses is_null() to check if $replacement was provided, however the previous default value was false.

Props shaampk1, felipeelia.
Fixes #48817.

#11 @shaampk1
5 years ago

Sure @felipeelia. Thank you for pointing out the bug.

Thank you @SergeyBiryukov for all the help getting me through this and accepting my contribution. It means a lot _ really.

Note: See TracTickets for help on using tickets.