[wp-trac] [WordPress Trac] #54028: Fix improper use of the hooks API
WordPress Trac
noreply at wordpress.org
Fri Aug 27 19:43:07 UTC 2021
#54028: Fix improper use of the hooks API
--------------------------+-------------------------
Reporter: azaozz | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.9
Component: General | Version: 5.8
Severity: normal | Keywords: needs-patch
Focuses: |
--------------------------+-------------------------
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:
- https://github.com/WordPress/wordpress-develop/blob/master/src/wp-admin
/edit-form-blocks.php#L32
- https://github.com/WordPress/wordpress-develop/blob/master/src/wp-admin
/options-privacy.php#L21
- https://github.com/WordPress/wordpress-develop/blob/master/src/wp-admin
/privacy-policy-guide.php#L20
- https://github.com/WordPress/wordpress-develop/blob/master/src/wp-
includes/script-loader.php#L2448
- https://github.com/WordPress/wordpress-develop/blob/master/src/wp-
includes/sitemaps/class-wp-sitemaps-renderer.php#L254
(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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54028>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list