Make WordPress Core

Opened 5 months ago

Last modified 2 weeks ago

#54028 new defect (bug)

Fix improper use of the hooks API

Reported by: azaozz Owned by:
Milestone: 6.0 Priority: normal
Severity: normal Version: 5.8
Component: General Keywords: has-patch
Focuses: docs Cc:


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.

Change History (7)

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

5 months ago

  • 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
2 months ago

#54367 was marked as a duplicate.

#5 @hellofromTonya
7 weeks 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
2 weeks ago

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

Note: See TracTickets for help on using tickets.