Block Visibility: Support non-inline Forms #744
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves compatibility with the third-party Block Visibility plugin, which adds visibility controls to Gutenberg blocks, including Kit's Form block. It allows blocks to be shown or hidden based on various conditions.
For example, users can place a Form block in a theme's footer and set it to display only on specific parts of the site, such as excluding certain Posts by Category. This addresses a reported use case where a non-inline Form needs to appear site-wide except on Posts assigned to a specific Category.
By default, Block Visibility works well with our Form block. However, due to how we defer non-inline Form scripts to the footer (to avoid layout issues), the Form script remains on the page even when Block Visibility hides the Form block, because the script has already been queued for output before Block Visibility runs on WordPress'
render_block
filter.This PR improves compatibility by:
This prevents the non-inline Form script from being added to the footer, if the block is hidden, ensuring correct working functionality.
Testing
testFormBlockWithNonInlineFormAndBlockVisibilityPlugin
: Tests that a Form Block with a non-inline Form specified, with conditions meaning it won't display on the Page, results in the Form <script> tag not being output.Checklist