Make WordPress Core

Opened 21 months ago

Last modified 4 months ago

#54028 new defect (bug)

Fix improper use of the hooks API

Reported by: azaozz's profile azaozz Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.8
Component: General Keywords: has-patch
Focuses: docs Cc:

Description

Using lambda functions as callbacks for add_action() and add_filter() is not supported as it breaks part of the WP Hooks API. It prevents the removal of such callbacks, remove_action() and remove_filter() stop working.

It seems there are few cases of such breakage in core:

(and possibly other).

Generally hooks should be added to either wp-admin/includes/admin-filters.php or wp-includes/default-filters.php as much as possible. It's also acceptable to add them from functions or "template" files. However hooks should never be added from "include" files (for security reasons), and lambda callbacks are not acceptable.

Attachments (1)

54028.diff (6.1 KB) - added by johnregan3 15 months ago.
Diff of what is included in github PR 2401

Download all attachments as: .zip

Change History (16)

This ticket was mentioned in PR #1634 on WordPress/wordpress-develop by donmhico.


21 months ago
#2

  • Keywords has-patch added; needs-patch removed

This PR converts the lambda functions that adds body classes in the following pages:

New filters are as follows

  • body_class_edit_form_blocks
  • body_class_options_privacy

Trac ticket: https://core.trac.wordpress.org/ticket/54028

#4 @hellofromTonya
19 months ago

#54367 was marked as a duplicate.

#5 @hellofromTonya
18 months ago

  • Milestone changed from 5.9 to 6.0

With 5.9 Beta 1 happening in less than 4 hours, moving this ticket to 6.0.

#7 @johnregan3
17 months ago

Just an update to note I'm currently working on this ticket.

This ticket was mentioned in PR #2401 on WordPress/wordpress-develop by johnregan3.


15 months ago
#9

Trac ticket: https://core.trac.wordpress.org/ticket/54028

Fixes/updates hooks using lambda functions.
The list below is taken from the trac ticket.

Note that the two unaddressed issues below are lambda functions using use to pass data into the filter, and it would take serious work to correct these issues that may be beyond the scope of this ticket, which I believe is generally to "clean things up." I'm definitely open to advice on how to approach fixing these.

add_filter()

Bad example in docblock

add_action()

Mentioned in ticket, but no longer valid

Props to @donmhico and their PR.

#10 @johnregan3
15 months ago

PR issued for discussion. @azaozz @donmhico

#11 @audrasjb
15 months ago

I requested changes on a few Docblocks issues in the above PR, otherwise the patch looks good to me

@johnregan3
15 months ago

Diff of what is included in github PR 2401

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


13 months ago

#13 @costdev
13 months ago

  • Milestone changed from 6.0 to Future Release

Per the discussion in the bug scrub, I'm moving this ticket to Future Release as this still needs architectural decisions before it can proceed.

Last edited 13 months ago by costdev (previous) (diff)

This ticket was mentioned in Slack in #core-upgrade-install by sergey. View the logs.


4 months ago

Note: See TracTickets for help on using tickets.