-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix injection of script in Categories block when dropdown displayed #25026
Conversation
Size Change: 0 B Total Size: 1.17 MB ℹ️ View Unchanged
|
It may be best to revert the change that introduced the regression rather than work around the block root limitation: #25028 It was not intended to limit the output in such a way. Thanks for the detailed report! |
In any case, this PR should still be merged because the location for the JS injection was not ideal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've confirmed the regression (still present in current master
) and the fix. This is working well, thanks!
While I think this is a good fix, ideally the block-supports hook shouldn't drop the extra markup if not added under the wrapper. |
I agree, is a workaround for a regression but should be considered complementary to the fix in #25028 and not a replacement. |
… to run now that WordPress/gutenberg#25026 has been merged
… to run now that WordPress/gutenberg#25026 has been merged (#5347)
… to run now that WordPress/gutenberg#25026 has been merged (#5347)
Description
Unit tests for the AMP plugin started failing once Guenberg v8.9.0: ampproject/amp-wp#5319 (comment). The issue was traced back to 7fbdda2 as part of #25020.
Currently, when a Categories block is added and the "Display as dropdown" option is enabled, selecting a category in the dropdown has no effect. This is because the script constructed by
build_dropdown_script_block_core_categories()
is no longer making it into the page. The reason is thatgutenberg_render_block_core_categories()
is appending the script to the$wrapper_markup
so it is outside of the block wrapper, but after 7fbdda2 only the block wrapper ($block_root
) is returned bygutenberg_apply_block_supports()
.This PR fixes that problem by ensuring that
<script>
returned bybuild_dropdown_script_block_core_categories()
is inserted immediately after the</select>
closing tag and is placed on the inside of the$items_markup
rather than being inserted after the$wrapper_markup
.This should also prevent the
sprintf()
call from failing if someone has a category containing string formats.How has this been tested?
Add a Categories block to the content and enable the "Display as dropdown" option. Before this PR, no
<script>
is added with the block. With this PR, a<script>
is added and selecting a category causes navigation to the category.Screenshots
Before
After
Types of changes
Bug fix (a regression)
Checklist: