Changelog: Pro preview teaser + upsell menu (free) - #328
Conversation
- Locked "Changelog" settings tab in the free plugin (ProPreviews) shown when Pro is inactive, matching the existing preview/overlay pattern. - "Changelogs" admin submenu under weDocs (after Docs) that opens a Pro upsell page, registered only when Pro is not active.
WalkthroughAdds a "Changelogs" admin submenu upsell (ChangelogUpsell class) shown under weDocs menu when Pro is inactive, wired into Admin.php's constructor. Adds a corresponding React ChangelogSettings preview component registered in ProPreviews' settings menu and templates when Pro is not loaded. ChangesChangelog Upsell Feature
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.2.2)PHP Fatal error: Uncaught Error: Undefined constant "ABSPATH" in /includes/functions.php:423 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@includes/Admin/ChangelogUpsell.php`:
- Around line 57-80: The reorder_menu method in ChangelogUpsell currently
inserts the wedocs-changelog entry at a fixed position, which can place it
before the Docs item. Update the logic to find the existing Docs submenu entry
within $submenu['wedocs'] and splice the Changelogs item immediately after that
entry instead of always using index 1. Keep the existing checks for
is_pro_active() and the wedocs submenu, and reuse the current $submenu['wedocs']
traversal in reorder_menu to locate both items robustly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5726ddae-4b75-429d-97a8-08f12b7d634c
📒 Files selected for processing (4)
includes/Admin.phpincludes/Admin/ChangelogUpsell.phpsrc/components/ProPreviews/ChangelogSettings.jssrc/components/ProPreviews/index.js
| public function reorder_menu() { | ||
| global $submenu; | ||
|
|
||
| if ( $this->is_pro_active() || empty( $submenu['wedocs'] ) ) { | ||
| return; | ||
| } | ||
|
|
||
| $index = null; | ||
| foreach ( $submenu['wedocs'] as $i => $item ) { | ||
| if ( isset( $item[2] ) && 'wedocs-changelog' === $item[2] ) { | ||
| $index = $i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if ( null === $index ) { | ||
| return; | ||
| } | ||
|
|
||
| $entry = $submenu['wedocs'][ $index ]; | ||
| unset( $submenu['wedocs'][ $index ] ); | ||
| $submenu['wedocs'] = array_values( $submenu['wedocs'] ); | ||
| array_splice( $submenu['wedocs'], 1, 0, [ $entry ] ); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect how the Docs submenu page is registered to confirm it always lands at index 0
rg -n "add_submenu_page|add_menu_page" includes/Admin/Docs_List_Table.php includes/Admin.phpRepository: weDevsOfficial/wedocs-plugin
Length of output: 166
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the admin files and inspect menu registration / submenu ordering logic.
git ls-files | rg '^(includes/Admin/|includes/Admin\.php|includes/Admin/Docs_List_Table\.php)'
printf '\n--- search ---\n'
rg -n "add_submenu_page|add_menu_page|wedocs-changelog|wedocs'" includes/Admin includes -g '!vendor' || trueRepository: weDevsOfficial/wedocs-plugin
Length of output: 50384
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Map the relevant file structure and read the target file around the commented lines.
fd -a "ChangelogUpsell.php|Admin.php|Docs_List_Table.php" .
printf '\n--- outline ---\n'
ast-grep outline includes/Admin/ChangelogUpsell.php --view expanded || true
printf '\n--- target lines ---\n'
sed -n '1,160p' includes/Admin/ChangelogUpsell.php | cat -nRepository: weDevsOfficial/wedocs-plugin
Length of output: 6091
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the submenu registration block to see whether "Docs" is intentionally inserted first.
sed -n '1,170p' includes/Admin/Menu.php | cat -nRepository: weDevsOfficial/wedocs-plugin
Length of output: 4430
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Check whether anything can prepend or otherwise reorder the wedocs submenu items.
rg -n "wedocs_submenu|add_submenu_page\(\s*'wedocs'|add_submenu_page\(\s*\"wedocs\"" includes .Repository: weDevsOfficial/wedocs-plugin
Length of output: 370
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "wedocs_submenu|add_submenu_page\(\s*'wedocs'|add_submenu_page\(\s*\"wedocs\"" includes .Repository: weDevsOfficial/wedocs-plugin
Length of output: 370
🌐 Web query:
WordPress add_menu_page automatically adds first submenu item same slug index 0 submenu order
💡 Result:
In WordPress, when you add a custom top-level menu using add_menu_page, WordPress automatically creates a first submenu item that shares the same name and slug as the parent menu [1][2]. This is default behavior intended to ensure the top-level menu has a clickable page associated with it [3][2]. To manage or remove this duplicate first submenu item, developers typically use one of the following approaches: 1. Matching Slugs (Common Pattern): You can make the top-level menu and the first submenu share the exact same menu_slug [4][2]. This causes the submenu item to effectively override or merge with the parent's default submenu, which is a standard technique when you want the top-level link to point to a specific page or when you want to avoid the appearance of a redundant sub-item [4][5]. 2. Removing the Submenu: You can explicitly remove the automatically generated submenu item using the remove_submenu_page function after it has been registered [1][6]. This is done within an action hooked to admin_menu, ensuring it runs after the menu creation: remove_submenu_page( 'parent_slug', 'menu_slug'); 3. Manipulating the Global Submenu Variable: For more granular control, developers sometimes unset the item directly from the global $submenu array [7]. This is often considered a less "clean" method than using the provided API functions, but it allows for total removal of the index entry that WordPress generates [7]. 4. Using a Dummy Capability: Some developers set a capability that the current user does not have (e.g., 'do_not_allow') for the parent menu, preventing the submenu from appearing or behaving in specific ways, though this can hide the menu entirely if not handled carefully with subsequent add_submenu_page calls that use the correct capabilities [8]. If your goal is to have the top-level menu name be different from the first submenu item, the recommended approach is to ensure the first submenu item is registered with a matching slug as the parent, which prevents the duplication of the label [4][2]. If you wish to entirely remove the first submenu entry from the sidebar, using remove_submenu_page is the most standard and supported method [1].
Citations:
- 1: https://wordpress.stackexchange.com/questions/52675/how-to-remove-duplicate-link-from-add-menu-page
- 2: https://codex.wordpress.org/Administration_Menus
- 3: https://wordpress.stackexchange.com/questions/315963/how-to-avoid-creating-first-submenu-page-that-is-same-as-menu-page
- 4: https://developer.wordpress.org/reference/functions/add_menu_page/?output_format=md
- 5: https://stackoverflow.com/questions/26190544/wordpress-admin-custom-menu-title-repeat-on-sub-menu
- 6: https://wordpress.stackexchange.com/questions/66498/add-menu-page-with-different-name-for-first-submenu-item
- 7: https://stackoverflow.com/questions/18327471/add-submenu-page-doesnt-display-submenu-if-menu-slug-is-the-same-as-in-top-menu
- 8: https://wordpress.stackexchange.com/questions/430152/admin-adding-submenu-that-has-the-same-destination-as-the-parent-menu
Insert Changelogs after the Docs item, not at a fixed index. WordPress keeps the parent wedocs submenu in the array, and this class appends Changelogs at position 1, which puts it before Docs in the default order. Find the Docs entry and splice after it instead.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@includes/Admin/ChangelogUpsell.php` around lines 57 - 80, The reorder_menu
method in ChangelogUpsell currently inserts the wedocs-changelog entry at a
fixed position, which can place it before the Docs item. Update the logic to
find the existing Docs submenu entry within $submenu['wedocs'] and splice the
Changelogs item immediately after that entry instead of always using index 1.
Keep the existing checks for is_pro_active() and the wedocs submenu, and reuse
the current $submenu['wedocs'] traversal in reorder_menu to locate both items
robustly.
Free-side support for the Pro Changelog module.
wedocs_pro_loaded).Pairs with weDevsOfficial/wedocs-pro#342.
Summary by CodeRabbit
New Features
Bug Fixes