WordPress.org

Make WordPress Core

Opened 7 weeks ago

Last modified 7 weeks ago

#54028 new defect (bug)

Fix improper use of the hooks API

Reported by: azaozz Owned by:
Milestone: 5.9 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.

Change History (3)

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


7 weeks 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

Note: See TracTickets for help on using tickets.