Fix: Use add_filter() for get_block_type_variations hook#76297
Fix: Use add_filter() for get_block_type_variations hook#76297talldan merged 1 commit intoWordPress:trunkfrom
Conversation
The `get_block_type_variations` hook is invoked via `apply_filters()`, so it should be registered with `add_filter()` instead of `add_action()`.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @apermo! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
talldan
left a comment
There was a problem hiding this comment.
LGTM, thanks for fixing.
What?
Closes #76296
Changes
add_action()toadd_filter()for theget_block_type_variationshook in the Navigation Link block.Why?
The
get_block_type_variationshook is fired viaapply_filters()in WordPress Core, making it a filter hook. Usingadd_action()is semantically incorrect, even though it works becauseadd_action()callsadd_filter()internally.The hook is invoked here:
https://github.com/WordPress/wordpress-develop/blob/64086b2a15ef4ccf6443de2056646da1ee17d56d/src/wp-includes/class-wp-block-type.php#L608-L616
The callback function already returns as expected:
gutenberg/packages/block-library/src/navigation-link/index.php
Lines 381 to 419 in fbeaf97
How?
Replaced
add_action()withadd_filter()inpackages/block-library/src/navigation-link/index.php.Testing Instructions
add_action()is an alias foradd_filter()internally.Testing Instructions for Keyboard
N/A — no UI changes.
This PR was authored by Claude Code (AI), steered and reviewed by @apermo.