isUserPremium = alertboxblock_is_premium(); } public function adminMenu() { // Always nest the dashboard as a "Help & Demos" submenu under the // Alert Box CPT menu, for all users. add_submenu_page( 'edit.php?post_type=' . ABB_PostType::POST_TYPE, __('Help & Demos - bPlugins', 'alert-box-block'), __('Help & Demos', 'alert-box-block'), 'manage_options', self::PAGE_SLUG, [$this, 'renderDashboardPage'] ); } public function restoreDashboardMenu() { global $submenu, $menu; $has = function ( $parent ) use ( &$submenu ) { foreach ( isset( $submenu[ $parent ] ) ? $submenu[ $parent ] : [] as $item ) { if ( isset( $item[2] ) && self::PAGE_SLUG === $item[2] ) { return true; } } return false; }; // Keeps the page reachable at edit.php?post_type=alert-box-block&page=alert-box-block-dashboard. $cpt = 'edit.php?post_type=' . ABB_PostType::POST_TYPE; if ( ! $has( $cpt ) ) { $this->adminMenu(); } // Freemius also swaps the top-level item to its own page slug, which hides // the CPT submenu — so show "Help & Demos" under that item as well. foreach ( (array) $menu as $item ) { $slug = isset( $item[2] ) ? $item[2] : ''; if ( 'alert-box-block' === $slug && ! $has( $slug ) ) { add_submenu_page( $slug, __( 'Help & Demos - bPlugins', 'alert-box-block' ), __( 'Help & Demos', 'alert-box-block' ), 'manage_options', self::PAGE_SLUG, [ $this, 'renderDashboardPage' ] ); } } } // Before 2.1.0 the free dashboard lived at Tools → Alert Box Block; send old bookmarks to the new page. public function redirectLegacyPage() { global $pagenow; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only redirect. if ( 'tools.php' === $pagenow && isset( $_GET['page'] ) && 'alert-box-block' === $_GET['page'] ) { wp_safe_redirect( alertboxblock_dashboard_url() ); exit; } } public function renderDashboardPage(){ ?>