From 4cdcd5b069182db180a1b23de7d69af2eeb4a335 Mon Sep 17 00:00:00 2001 From: Pierre Lannoy Date: Wed, 11 Aug 2021 09:41:20 +0200 Subject: [PATCH] Removes unneeded menus. --- admin/class-apcu-manager-admin.php | 9 +++++++++ includes/plugin/class-core.php | 3 ++- perfopsone/class-menus.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/admin/class-apcu-manager-admin.php b/admin/class-apcu-manager-admin.php index c438383..5d10047 100755 --- a/admin/class-apcu-manager-admin.php +++ b/admin/class-apcu-manager-admin.php @@ -143,6 +143,15 @@ public function finalize_admin_menus() { Menus::finalize(); } + /** + * Removes unneeded items from the settings menu. + * + * @since 2.0.0 + */ + public function normalize_admin_menus() { + Menus::normalize(); + } + /** * Set the items in the settings menu. * diff --git a/includes/plugin/class-core.php b/includes/plugin/class-core.php index 3ce3062..e491396 100755 --- a/includes/plugin/class-core.php +++ b/includes/plugin/class-core.php @@ -114,7 +114,8 @@ private function define_admin_hooks() { $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'init_admin_menus' ); - $this->loader->add_action( 'admin_menu', $plugin_admin, 'finalize_admin_menus', PHP_INT_MAX ); + $this->loader->add_action( 'admin_menu', $plugin_admin, 'finalize_admin_menus', PHP_INT_MAX - 1 ); + $this->loader->add_action( 'admin_menu', $plugin_admin, 'normalize_admin_menus', PHP_INT_MAX ); $this->loader->add_action( 'admin_init', $plugin_admin, 'init_settings_sections' ); $this->loader->add_filter( 'plugin_action_links_' . plugin_basename( APCM_PLUGIN_DIR . APCM_SLUG . '.php' ), $plugin_admin, 'add_actions_links', 10, 4 ); $this->loader->add_filter( 'plugin_row_meta', $plugin_admin, 'add_row_meta', 10, 2 ); diff --git a/perfopsone/class-menus.php b/perfopsone/class-menus.php index 487c586..de5bd06 100644 --- a/perfopsone/class-menus.php +++ b/perfopsone/class-menus.php @@ -106,6 +106,20 @@ public static function initialize() { } } + /** + * Dispatch the admin menus. + * + * @since 2.0.0 + */ + public static function normalize() { + $current = apply_filters( 'init_perfopsone_admin_menus', [] ); + foreach ( self::$menus_positions as $menu ) { + if ( ! array_key_exists( $menu, $current ) ) { + remove_submenu_page( 'perfopsone-dashboard', 'perfopsone-' . $menu ); + } + } + } + /** * Dispatch the admin menus. *