From c773a21c252c0c515a22d8e88c90855ea7ce3e7a Mon Sep 17 00:00:00 2001 From: David Keane Date: Mon, 25 May 2026 07:54:54 +0100 Subject: [PATCH] fix: stop the duplicate "Create a New WP Note" form rendering at the bottom of My Notes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CHANGELOG.md | 22 ++++++++++++++++++++++ wp-notes.php | 16 ++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260b134..2d3ed5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,28 @@ Format: [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/) — versi ## [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 The "No active notes found" / "No completed notes found" inline notice on the My Notes page rendered with `class="notice notice-info"` diff --git a/wp-notes.php b/wp-notes.php index 8921a06..6a1c222 100644 --- a/wp-notes.php +++ b/wp-notes.php @@ -177,16 +177,24 @@ function wp_notes_admin_menu() { 3 ); - // "My Notes" — the main landing submenu (same slug as the parent - // menu, so clicking either WP Notes or My Notes lands on the same - // central dashboard: create form + active list + completed list). + // "My Notes" — the main landing submenu. Same slug as the parent + // menu so clicking either WP Notes or My Notes lands on the same + // 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( 'wp-notes', // Parent slug 'My Notes', // Page title (browser tab) 'My Notes', // Menu label (sidebar) 'manage_options', // Capability 'wp-notes', // Menu slug (matches parent → same page) - 'wp_notes_create_page' // Renderer + '' // Empty callback — see comment above ); // Settings submenu