v0.19.1 - hotfix: Board admin page 404 (submenu registered before parent menu) (#157)
Board submenu now registers at admin_menu priority 11 (parent toplevel at 10) so the page hook lands under prautoblogger_page_prautoblogger-board; $submenu reordered defensively to keep Board the first item / top-level click target. Enqueue gate now matches; board.css/board.js load for the first time on prod. Regression test: BoardMenuRegistrationTest (fails on pre-fix main). QA: APPROVE-W-P2 qa-reviews/prautoblogger/2026-06-12-6168520.md Thread: convo/prautoblogger/threads/2026-06-pipeline-v2-phase2-admin/ seq 11-14 Agent-Session: cto-board-404-hotfix-merge-20260612
This commit is contained in:
@@ -42,6 +42,14 @@ class PRAutoBlogger_Board_Page {
|
||||
* submenu duplicate of the top-level page; we name it "Board" so the
|
||||
* first click goes to the board, not the raw settings page.
|
||||
*
|
||||
* Registration order note: this method is hooked at admin_menu priority 11
|
||||
* so that PRAutoBlogger_Admin_Page::on_register_menu() (priority 10) has
|
||||
* already called add_menu_page(). This ensures WordPress has populated
|
||||
* $admin_page_hooks['prautoblogger-settings'] before add_submenu_page()
|
||||
* runs here, so get_plugin_page_hookname() resolves to the correct
|
||||
* 'prautoblogger_page_prautoblogger-board' suffix rather than the fallback
|
||||
* 'admin_page_prautoblogger-board'. See ARCHITECTURE.md §Board.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function on_register_menu(): void {
|
||||
@@ -54,6 +62,30 @@ class PRAutoBlogger_Board_Page {
|
||||
self::PAGE_SLUG,
|
||||
array( $this, 'render_page' )
|
||||
);
|
||||
|
||||
// Reorder submenu so Board is the FIRST entry (primary click target).
|
||||
// WordPress auto-appended a duplicate of the top-level page as submenu
|
||||
// index 0; our Board was appended at index 1. We swap them so the
|
||||
// top-level PRAutoBlogger click lands on the Board page, not Settings.
|
||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- intentional submenu reorder.
|
||||
global $submenu;
|
||||
if ( isset( $submenu['prautoblogger-settings'] ) ) {
|
||||
$items = $submenu['prautoblogger-settings'];
|
||||
// Find the Board entry and move it to position 0.
|
||||
$board_idx = null;
|
||||
foreach ( $items as $i => $item ) {
|
||||
if ( isset( $item[2] ) && self::PAGE_SLUG === $item[2] ) {
|
||||
$board_idx = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( null !== $board_idx && $board_idx > 0 ) {
|
||||
$board_item = $items[ $board_idx ];
|
||||
unset( $items[ $board_idx ] );
|
||||
// Prepend board item at position 0 while preserving remaining order.
|
||||
$submenu['prautoblogger-settings'] = array_merge( array( $board_item ), array_values( $items ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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' ) );
|
||||
|
||||
Reference in New Issue
Block a user