Fix injection of script in Categories block when dropdown displayed#25026
Fix injection of script in Categories block when dropdown displayed#25026youknowriad merged 1 commit intomasterfrom
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. |
sirreal
left a comment
There was a problem hiding this comment.
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_markupso 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_markuprather 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: