get_toplevel_menu_icon_url(); $page_title = $this->get_toplevel_menu_title(); add_menu_page( $page_title, $page_title, 'manage_options', ACADEMY_PLUGIN_SLUG, [ $this, 'load_main_template' ], $icon_url, 2 ); foreach ( Helper::get_admin_menu_list() as $item_key => $item ) { add_submenu_page( $item['parent_slug'], $item['title'], $item['title'], $item['capability'], $item_key, [ $this, 'load_main_template' ] ); } // "About" — registered as a real submenu so ?page=academy-about // resolves and passes the admin-page access check, but hidden from the // visible menu via CSS (add_admin_menu_css). It is shown once per update // instead of via a permanent menu item. $about = ACADEMY_PLUGIN_SLUG . '-about'; add_submenu_page( ACADEMY_PLUGIN_SLUG, __( 'About', 'academy' ), __( 'About', 'academy' ), 'manage_options', $about, [ $this, 'load_main_template' ] ); } /** * Show the "About" page once after each plugin update. * * Driven entirely by the version bump: Migration::run_migration() sets the * `academy_show_whats_new` flag when ACADEMY_VERSION changes (updates only, * not fresh installs). This just consumes that flag once — redirecting to * the About page from ANY screen the first safe request after the update, * then clearing the flag so it never fires again until the next version bump. * Contexts where a redirect would break something (the update/install flow, * bulk/row actions, form POSTs) are skipped so it lands on the next safe page. * * @return void */ public function maybe_redirect_about() { if ( wp_doing_ajax() || wp_doing_cron() || is_network_admin() || ! current_user_can( 'manage_options' ) ) { return; } // Nothing to do unless the migrator flagged a version change. if ( ! get_option( 'academy_show_whats_new' ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; $about = ACADEMY_PLUGIN_SLUG . '-about'; // Already on the About page → clear the flag and stop redirecting. if ( $about === $page ) { delete_option( 'academy_show_whats_new' ); return; } // Don't hijack the update/install flow, bulk or row actions, or form // submissions — let those complete and fire on the next plain page view // (the flag survives, so the redirect still happens next safe request). global $pagenow; $blocked_pages = [ 'update.php', 'update-core.php', 'plugins.php', 'plugin-install.php', 'admin-post.php', 'options.php', 'async-upload.php', 'media-upload.php' ]; if ( in_array( $pagenow, $blocked_pages, true ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( 'GET' !== strtoupper( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ?? 'GET' ) ) ) || isset( $_GET['action'] ) ) { return; } // Clear before redirecting so a failed redirect can't cause a loop. delete_option( 'academy_show_whats_new' ); wp_safe_redirect( admin_url( 'admin.php?page=' . $about ) ); exit; } // Menu visibility for `academy_manager` (academy/openspec/changes/academy-manager-role/) // is deliberately NOT handled here. That role carries no capabilities of // its own beyond a marker, so a holder is routed through the exact same // per-area menu filtering every other Manage Roles staff member already // gets from the pro `role-permission` addon's own // `AcademyProRolePermission\Menu::filter_menu_for_staff()` / // `relax_top_level()` — a blanket "show everything" version lived here // briefly and was reverted once it defeated per-area granularity. public function load_main_template() { $preloader_html = apply_filters( 'academy/preloader', academy_get_preloader_html() ); echo '
' . wp_kses_post( $preloader_html ) . '
'; } public function get_toplevel_menu_title() { return apply_filters( 'academy/admin/toplevel_menu_title', __( 'Academy LMS', 'academy' ) ); } public function get_toplevel_menu_icon_url() { // phpcs:disable if ( isset( $_GET['page'] ) && 'academy' === $_GET['page'] ) { $icon_url = 'data:image/svg+xml;base64, ' . base64_encode( file_get_contents( ACADEMY_ASSETS_DIR_PATH . 'images/logo-white.svg' ) ); return apply_filters( 'academy/admin/toplevel_active_menu_icon', $icon_url ); } $icon_url = 'data:image/svg+xml;base64, ' . base64_encode( file_get_contents( ACADEMY_ASSETS_DIR_PATH . 'images/admin-logo.svg' ) ); return apply_filters( 'academy/admin/toplevel_inactive_menu_icon', $icon_url ); } public function get_logo_url(){ return apply_filters( 'academy/admin/logo_url', ACADEMY_ASSETS_URI . 'images/logo.svg' ); } function add_admin_menu_css() { echo ''; } }