Skip to content
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

Block Visibility: Support non-inline Forms #744

Conversation

n7studios
Copy link
Contributor

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.

Screenshot_2024-11-21_at_16_25_53

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:

  • checking if the Block Visibility plugin is active,
  • if so, runs visibility checks for the Form block earlier on in the request

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

@n7studios n7studios self-assigned this Nov 21, 2024
@n7studios n7studios changed the base branch from main to fix-cron-tests November 25, 2024 05:13
… into add-block-visibility-support-non-inline-forms
@n7studios n7studios requested review from a team, noelherrick and corydhmiller and removed request for a team November 26, 2024 01:03
@n7studios n7studios marked this pull request as ready for review November 26, 2024 01:03
@n7studios n7studios changed the base branch from fix-cron-tests to fix-tests-doing-it-wrong-notice November 26, 2024 01:03
Copy link
Contributor

@noelherrick noelherrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed comments.

@n7studios n7studios merged commit cd7bb60 into fix-tests-doing-it-wrong-notice Nov 27, 2024
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants