fix: Board admin submenu 404 — register after parent menu (v0.19.1)

Root cause: PRAutoBlogger_Board_Page::on_register_menu was hooked at
admin_menu default priority 10, same as PRAutoBlogger_Admin_Page::on_register_menu,
but registered first in register_admin_hooks(). WordPress calls
get_plugin_page_hookname() at add_submenu_page() time; if add_menu_page()
has not yet fired, $admin_page_hooks['prautoblogger-settings'] is unset and
WP falls back to the admin_page_prautoblogger-board hookname. At request
time WP recomputes the hookname as prautoblogger_page_prautoblogger-board,
finds no registered callback, and calls wp_die() — 404. Same mismatch
prevented board.css and board.js from loading (enqueue gate also checks
prautoblogger_page_ prefix).

Fix:
- class-prautoblogger.php: parent menu (Admin_Page) stays at priority 10;
  board submenu (Board_Page) moves to priority 11. Explicit priorities added
  with explanatory comment. See ARCHITECTURE.md §Board for the constraint.
- class-board-page.php: add $submenu reorder in on_register_menu() to keep
  Board as the first submenu item (primary click target), since the board
  entry can no longer be prepended by the auto-duplicate mechanism.
- tests/unit/Admin/BoardMenuRegistrationTest.php: 4 tests (new file):
  (1) priority relationship regression guard — FAILS on unfixed code (both
      at 10), PASSES with fix (board at 11); (2) fixed execution order;
      (3) broken execution order documentation; (4) parent slug correctness.
- ARCHITECTURE.md: §22b updated with menu-ordering constraint.
- CHANGELOG.md: v0.19.1 entry.

Deletion audit: only intentional removals (old wrong-order registration block).
class-prautoblogger.php is 407 lines (was 400 pre-fix, pre-existing P2 debt).

Agent-Session: board-404-hotfix-20260612
This commit is contained in:
peptiderepo
2026-06-12 08:29:00 +00:00
parent 49f17c3d6f
commit 6168520504
6 changed files with 347 additions and 10 deletions

View File

@@ -67,16 +67,23 @@ class PRAutoBlogger {
/** Register admin-only hooks (settings, notices, metabox, dashboard widget). */
private function register_admin_hooks(): void {
// Kanban board -- registered first so it appears as the first submenu item.
$board_page = new PRAutoBlogger_Board_Page();
add_action( 'admin_menu', array( $board_page, 'on_register_menu' ) );
add_action( 'admin_enqueue_scripts', array( $board_page, 'on_enqueue_assets' ) );
// Parent top-level menu first (priority 10), then Board submenu (priority 11).
// WHY: WordPress computes the page hookname via get_plugin_page_hookname() at
// add_submenu_page() time. If add_menu_page() has not yet fired, the parent
// slot in $admin_page_hooks is unset and WP falls back to the `admin_page_*`
// hookname. At request time WP recomputes the hookname as `prautoblogger_page_*`
// and finds no registered callback -> wp_die 404. Fixing priority ensures the
// parent slot is populated before the submenu call. See ARCHITECTURE.md §Board.
$admin_page = new PRAutoBlogger_Admin_Page();
add_action( 'admin_menu', array( $admin_page, 'on_register_menu' ) );
add_action( 'admin_menu', array( $admin_page, 'on_register_menu' ), 10 );
add_action( 'admin_init', array( $admin_page, 'on_register_settings' ) );
add_action( 'admin_enqueue_scripts', array( $admin_page, 'on_enqueue_assets' ) );
// Board at priority 11 -- fires AFTER add_menu_page, so hookname is correct.
$board_page = new PRAutoBlogger_Board_Page();
add_action( 'admin_menu', array( $board_page, 'on_register_menu' ), 11 );
add_action( 'admin_enqueue_scripts', array( $board_page, 'on_enqueue_assets' ) );
add_action( 'admin_notices', array( new PRAutoBlogger_Admin_Notices(), 'on_display_notices' ) );
add_action( 'add_meta_boxes', array( new PRAutoBlogger_Post_Metabox(), 'on_register_metabox' ) );
add_action( 'admin_menu', array( new PRAutoBlogger_Metrics_Page(), 'on_register_menu' ) );