Skip to content

Widget Visibility: restore controls for legacy widgets in block widget editor#50015

Draft
agent-sandbox-automattic[bot] wants to merge 2 commits into
trunkfrom
ai/agent/jetpack-1757-1782507932
Draft

Widget Visibility: restore controls for legacy widgets in block widget editor#50015
agent-sandbox-automattic[bot] wants to merge 2 commits into
trunkfrom
ai/agent/jetpack-1757-1782507932

Conversation

@agent-sandbox-automattic

@agent-sandbox-automattic agent-sandbox-automattic Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Fixes JETPACK-1757
Fixes #49860

Proposed changes

In the Gutenberg block-based widget editor (Appearance > Widgets, available since WordPress 5.8), the "Visibility" button for legacy PHP widgets was rendered by PHP via in_widget_form but clicking it had no effect — the conditions panel never appeared.

Two bugs were present:

  1. JS DOM mismatchwidget-conditions.js used closest('div.widget') to locate the widget container when the "Visibility" button was clicked. In the Gutenberg legacy-widget block the container element is .wp-block-legacy-widget__edit-form, not div.widget. The closest() call returned an empty jQuery set, so every subsequent operation on $widget silently did nothing. Fixed by extending the selector to 'div.widget, .wp-block-legacy-widget__edit-form' in the two affected event handlers.

  2. Assets not enqueued in Gutenbergwidget_admin_setup() (which enqueues widget-conditions.js, widget-conditions.css, and the widget_conditions_data global required by the block-editor visibility script) was registered on the sidebar_admin_setup action. In the Gutenberg block widget editor that action may not fire, so assets could silently be absent. For the Gutenberg path (!wp_use_widgets_block_editor() is false) we now register widget_admin_setup on enqueue_block_editor_assets instead, which reliably fires when the block editor page loads. The 'widgets' style handle (only registered in the classic editor) is also conditionally omitted as a CSS dependency to prevent a silent style-enqueue failure.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  1. Install Jetpack on a self-hosted WordPress site (WP 5.8+, block widget editor active by default).
  2. Enable the Widget Visibility module in Jetpack → Settings → Appearance.
  3. Go to Appearance → Widgets.
  4. Add or expand any legacy PHP widget (e.g. "Text", "Archives", "Recent Posts").
  5. Confirm the Visibility button appears at the bottom of the widget form.
  6. Click Visibility — the conditions panel should expand and allow adding rules (e.g. "Show if Page is Front page").
  7. Save the widget and confirm the rules persist.
  8. Verify the same flow still works in the Customizer → Widgets panel.
  9. Optionally verify the classic widget editor still works by disabling block widgets via add_filter('use_widgets_block_editor', '__return_false').

Linear: JETPACK-1757

Co-authored-by: nerrad darren.ethier@automattic.com

This PR was auto-generated by Agent Sandbox. Please review carefully before merging.

…t editor

In the Gutenberg block-based widget editor (Appearance > Widgets since
WordPress 5.8), the Visibility button for legacy PHP widgets was rendered
by PHP via `in_widget_form`, but clicking it did nothing.

Two bugs caused this:

1. `widget-conditions.js` used `closest('div.widget')` to find the widget
   container, but in the Gutenberg legacy-widget block the container is
   `.wp-block-legacy-widget__edit-form`, not `div.widget`.  The jQuery
   call returned an empty set, so every subsequent DOM operation on
   `$widget` silently did nothing (the conditions panel never toggled).

2. `widget_admin_setup()` (which enqueues the CSS/JS and localises the
   `widget_conditions_data` global) was wired to the `sidebar_admin_setup`
   action.  In the Gutenberg block widget editor that action may not fire,
   meaning the assets were never enqueued.  For the Gutenberg path we now
   register on `enqueue_block_editor_assets` instead, which reliably fires
   on the widgets.php block-editor page.  The `widgets` style handle (only
   registered in the classic editor) is also skipped as a CSS dependency
   when the block editor is active to prevent a silent enqueue failure.

Co-authored-by: nerrad <darren.ethier@automattic.com>
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the ai/agent/jetpack-1757-1782507932 branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack ai/agent/jetpack-1757-1782507932

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Feature] Widget Visibility [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Jun 26, 2026
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: July 7, 2026
    • Code freeze: July 6, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 26, 2026
@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php 63/636 (9.91%) -0.05% 3 ❤️‍🩹

Full summary · PHP report · JS report

Wrap the .closest().find().click() chain across lines to satisfy
prettier/prettier, which was failing ESLint (and in turn the linter
exclude-list check, which tried to add the file to the eslint excludelist).
@kraftbj

kraftbj commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

My initial read is that this is a no-op. The functionality appears to be working for me on trunk. Replied back to the issue to the OP asking for more details in order to reproduce the failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Widget Visibility [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Visibility Controls lost in new WP widgets control area

2 participants