fix: stop the duplicate "Create a New WP Note" form rendering at the bottom of My Notes
WordPress registers BOTH the parent menu's callback AND a submenu's callback against the same page hook when they share a menu_slug, and runs both in registration order. The My Notes submenu was passing wp_notes_create_page as its callback (a separate bare-form renderer used by the Tools-menu shortcut), so its output was being appended below the main page content — appearing as a duplicate "Create a New WP Note" form at the bottom of the My Notes page. The submenu now passes an empty string as the callback — the standard WP pattern when a submenu just relabels the parent (same slug, same target page). Only the parent's wp_notes_page_callback renders now. The wp_notes_create_page function is unchanged and still serves the Tools → My Notes shortcut at ?page=wp-notes-create. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,28 @@ Format: [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/) — versi
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed — Duplicate "Create a New WP Note" form at the bottom of My Notes
|
||||||
|
A second, bare-bones *"Create a New WP Note"* form was being
|
||||||
|
rendered at the **bottom** of the My Notes page, below the active
|
||||||
|
and completed lists. The form at the **top** (the proper `Add New
|
||||||
|
Note` postbox with color/size/font/emoji controls) is the intended
|
||||||
|
one — the bottom one was a duplicate, redundant from a UX standpoint.
|
||||||
|
|
||||||
|
**Root cause:** WordPress registers BOTH the parent menu's callback
|
||||||
|
AND a submenu's callback against the same page hook when the two
|
||||||
|
share a `menu_slug`. When `?page=wp-notes` is requested, both fire
|
||||||
|
in registration order. The submenu was passing `wp_notes_create_page`
|
||||||
|
as its callback (a separate bare-form renderer used by the
|
||||||
|
Tools-menu shortcut), so its output was getting appended below the
|
||||||
|
main page.
|
||||||
|
|
||||||
|
**Fix:** the My Notes submenu now passes an **empty string** as the
|
||||||
|
callback — the standard WP pattern when a submenu just relabels the
|
||||||
|
parent (same slug, same target page). Only the parent's
|
||||||
|
`wp_notes_page_callback` renders now. The `wp_notes_create_page`
|
||||||
|
function is unchanged and still serves the Tools → My Notes
|
||||||
|
shortcut at `?page=wp-notes-create`.
|
||||||
|
|
||||||
### Fixed — Empty-state notice ("No notes found") now dismissible
|
### Fixed — Empty-state notice ("No notes found") now dismissible
|
||||||
The "No active notes found" / "No completed notes found" inline
|
The "No active notes found" / "No completed notes found" inline
|
||||||
notice on the My Notes page rendered with `class="notice notice-info"`
|
notice on the My Notes page rendered with `class="notice notice-info"`
|
||||||
|
|||||||
+12
-4
@@ -177,16 +177,24 @@ function wp_notes_admin_menu() {
|
|||||||
3
|
3
|
||||||
);
|
);
|
||||||
|
|
||||||
// "My Notes" — the main landing submenu (same slug as the parent
|
// "My Notes" — the main landing submenu. Same slug as the parent
|
||||||
// menu, so clicking either WP Notes or My Notes lands on the same
|
// menu so clicking either WP Notes or My Notes lands on the same
|
||||||
// central dashboard: create form + active list + completed list).
|
// central dashboard (the parent's wp_notes_page_callback already
|
||||||
|
// renders form + active list + completed list).
|
||||||
|
//
|
||||||
|
// CRITICAL: callback must be empty here. WordPress registers BOTH
|
||||||
|
// the parent's and the submenu's callbacks against the same page
|
||||||
|
// hook when slugs match, and runs them in order — passing
|
||||||
|
// wp_notes_create_page as the callback caused a duplicate
|
||||||
|
// "Create a New WP Note" form to render BELOW the main page
|
||||||
|
// content. Empty callback means only the parent's renderer fires.
|
||||||
add_submenu_page(
|
add_submenu_page(
|
||||||
'wp-notes', // Parent slug
|
'wp-notes', // Parent slug
|
||||||
'My Notes', // Page title (browser tab)
|
'My Notes', // Page title (browser tab)
|
||||||
'My Notes', // Menu label (sidebar)
|
'My Notes', // Menu label (sidebar)
|
||||||
'manage_options', // Capability
|
'manage_options', // Capability
|
||||||
'wp-notes', // Menu slug (matches parent → same page)
|
'wp-notes', // Menu slug (matches parent → same page)
|
||||||
'wp_notes_create_page' // Renderer
|
'' // Empty callback — see comment above
|
||||||
);
|
);
|
||||||
|
|
||||||
// Settings submenu
|
// Settings submenu
|
||||||
|
|||||||
Reference in New Issue
Block a user