Skip to content

Fix: keep parent menu + siblings visible on submenu pages#1

Open
rmorse wants to merge 1 commit intoverygoodplugins:mainfrom
rmorse:fix/submenu-parent-siblings-visibility
Open

Fix: keep parent menu + siblings visible on submenu pages#1
rmorse wants to merge 1 commit intoverygoodplugins:mainfrom
rmorse:fix/submenu-parent-siblings-visibility

Conversation

@rmorse
Copy link

@rmorse rmorse commented Jan 16, 2026

Problem

When viewing a plugin's submenu page, the extension hides the parent menu item (if non-core) and sibling submenu items, losing navigation context.

Cause

applyCleanUp() checked link.classList.contains('current') but WordPress sets wp-has-current-submenu on the parent li, not current on the a tag. Also cleanSubmenu() only showed items matching core slugs or having current class.

Fix

  1. Added check for wp-has-current-submenu class on parent li to detect active submenu state
  2. Pass showAll flag to cleanSubmenu() when parent has active submenu
  3. When showAll is true, mark all sibling submenu items as visible

@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved menu submenu visibility logic to better identify current menu items.
    • Enhanced submenu item state handling and URL parsing error handling for improved menu reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

The changes extend submenu visibility logic in content.js to recognize li elements with the 'wp-has-current-submenu' class as current items. A new showAll parameter is added to the cleanSubmenu function to force submenu items to be marked as core. The function includes logic to pre-emptively mark submenu items as core when links are missing or URL parsing fails.

Changes

Cohort / File(s) Summary
Submenu visibility and marking logic
content.js
Updated cleanSubmenu() function signature to accept showAll parameter (default false). Extended current submenu detection to treat li elements with 'wp-has-current-submenu' class as current. Added showAllItems flag derived from parent li's class to force bulk-core marking of submenu items. Introduced pre-emptive core marking when links are missing and graceful error handling for URL parsing failures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing menu visibility on submenu pages by keeping the parent menu and sibling items visible, which directly addresses the changeset.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the problem, cause, and the fix implemented, with good alignment to the code changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@content.js`:
- Around line 276-280: The early return when showAll is true prevents setting
the current highlight; update the logic in the block handling showAll (where
li.setAttribute('data-vgp-core', 'true') is called) to also set or preserve the
data-vgp-current attribute for the item that should be current (or explicitly
clear/set it based on currentItem state) before returning, or remove the early
return and let the subsequent current-item assignment code run so the current
element receives data-vgp-current while all elements still get data-vgp-core.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa627c4 and 0e3bb12.

📒 Files selected for processing (1)
  • content.js
🔇 Additional comments (3)
content.js (3)

238-240: LGTM!

The extended isCurrent check correctly identifies active submenu states by detecting the wp-has-current-submenu class on the parent li element. This aligns with WordPress's behavior where the parent menu item is marked with this class rather than adding current to the anchor tag.


264-265: LGTM!

The showAllItems flag correctly derives from the wp-has-current-submenu class presence and is properly passed to cleanSubmenu(). This ensures sibling submenu items remain visible when navigating within a plugin's submenu pages, maintaining navigation context.


302-305: LGTM!

The isCurrent detection for submenu items correctly checks multiple conditions that WordPress uses to mark current items, providing comprehensive coverage.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +276 to +280
// If showAll is true, mark all items as core to keep them visible
if (showAll) {
li.setAttribute('data-vgp-core', 'true');
return;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Consider setting data-vgp-current even when showAll is true.

When showAll is true, all items are marked as data-vgp-core but the actual current item won't receive the data-vgp-current attribute due to the early return. If your CSS uses data-vgp-current for highlighting the active submenu item, this could cause a styling inconsistency where the current item loses its visual emphasis.

If highlighting isn't needed in this scenario, the current implementation is fine.

Proposed fix to preserve current item highlighting
       // If showAll is true, mark all items as core to keep them visible
       if (showAll) {
         li.setAttribute('data-vgp-core', 'true');
-        return;
+        // Still check if this is the current item for styling purposes
+        const link = li.querySelector('a');
+        if (link && (link.classList.contains('current') || li.classList.contains('current'))) {
+          li.setAttribute('data-vgp-current', 'true');
+        } else {
+          li.removeAttribute('data-vgp-current');
+        }
+        return;
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// If showAll is true, mark all items as core to keep them visible
if (showAll) {
li.setAttribute('data-vgp-core', 'true');
return;
}
// If showAll is true, mark all items as core to keep them visible
if (showAll) {
li.setAttribute('data-vgp-core', 'true');
// Still check if this is the current item for styling purposes
const link = li.querySelector('a');
if (link && (link.classList.contains('current') || li.classList.contains('current'))) {
li.setAttribute('data-vgp-current', 'true');
} else {
li.removeAttribute('data-vgp-current');
}
return;
}
🤖 Prompt for AI Agents
In `@content.js` around lines 276 - 280, The early return when showAll is true
prevents setting the current highlight; update the logic in the block handling
showAll (where li.setAttribute('data-vgp-core', 'true') is called) to also set
or preserve the data-vgp-current attribute for the item that should be current
(or explicitly clear/set it based on currentItem state) before returning, or
remove the early return and let the subsequent current-item assignment code run
so the current element receives data-vgp-current while all elements still get
data-vgp-core.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant