*/ namespace RankMath_Monitor\Admin; use RankMath_Monitor\Runner; use RankMath_Monitor\Traits\Hooker; use MyThemeShop\Admin\Page; use RankMath_Monitor\Helper as GlobalHelper; defined( 'ABSPATH' ) || exit; /** * Admin_Menu class. * * @codeCoverageIgnore */ class Admin_Menu implements Runner { use Hooker; /** * Register hooks. */ public function hooks() { $this->action( 'init', 'register_pages' ); $this->action( 'admin_menu', 'fix_first_submenu', 999 ); $this->action( 'admin_head', 'icon_css' ); } /** * Register admin pages for plugin. */ public function register_pages() { // Dashboard / Welcome / About. new Page( 'rank-math-monitor', esc_html__( 'Rank Math', '404-monitor' ), array( 'position' => 80, 'capability' => 'manage_options', 'icon' => 'dashicons-chart-area', 'render' => Admin_Helper::get_view( 'dashboard' ), 'classes' => array( 'rank-math-page' ), 'assets' => array( 'styles' => array( 'rank-math-dashboard' => '' ), 'scripts' => array( 'rank-math-dashboard' => '' ), ), 'is_network' => is_network_admin() && GlobalHelper::is_plugin_active_for_network(), )); // Help & Support. new Page( 'rank-math-help', esc_html__( 'Help & Support', '404-monitor' ), array( 'position' => 99, 'parent' => 'rank-math-monitor', 'capability' => 'level_1', 'classes' => array( 'rank-math-page' ), 'render' => Admin_Helper::get_view( 'help-manager' ), 'assets' => array( 'styles' => array( 'rank-math-common' => '', 'rank-math-dashboard' => '' ), 'scripts' => array( 'rank-math-common' => '' ), ), )); } /** * Fix first submenu name. * * @TODO Why are we unsetting [0] and why we are saving transient. */ public function fix_first_submenu() { global $submenu; if ( ! isset( $submenu['rank-math-monitor'] ) ) { return; } if ( current_user_can( 'manage_options' ) && 'Rank Math' === $submenu['rank-math-monitor'][0][0] ) { $submenu['rank-math-monitor'][0][0] = esc_html__( 'Dashboard', '404-monitor' ); } else { unset( $submenu['rank-math-monitor'][0] ); } if ( empty( $submenu['rank-math-monitor'] ) ) { return; } // Store ID of first_menu item so we can use it in the Admin menu item. set_transient( 'rank_math_first_submenu_id', array_values( $submenu['rank-math-monitor'] )[0][2] ); } /** * Print icon CSS for admin menu bar. */ public function icon_css() { ?>