/** * Adds Dashboard navigation menus. * * @since 1.0.0 */ public function add_menu_pages() { global $submenu; $limited_mode = false; $view = MS_Model_Settings::get_special_view(); if ($view) { // A special view is displayed. Do not display other menu items. $pages = array(); $limited_mode = true; } elseif (MS_Plugin::is_wizard()) { // Submenus definition: Wizard mode $pages = $this->get_setup_menu_pages(); $limited_mode = true; } else { // Submenus definition: Normal mode $pages = $this->get_default_menu_pages(); if (MS_Plugin::is_network_wide() && !is_network_admin()) { $limited_mode = true; } } /** * Allow Add-ons and other plugins to add menu pages. * * A menu item is defined by an array containing the following members: * 'title' => '...', * 'slug' => '...', * 'function' => callback * * @var array */ $pages = apply_filters('ms_plugin_menu_pages', $pages, $limited_mode, $this); $page_keys = array_keys($pages); $slug = ''; if (isset($page_keys[0]) && $pages[$page_keys[0]]) { $slug = $pages[$page_keys[0]]['slug']; } if (empty($slug)) { self::$base_slug = self::MENU_SLUG; } else { self::$base_slug = self::MENU_SLUG . '-' . $slug; } /* * Create primary menu item: Membership. * * The menu title is not translatable because of a bug in WordPress core * https://core.trac.wordpress.org/ticket/18857 * Until this bug is closed the title (2nd argument) can't be translated */ add_menu_page('Membership 2', 'Membership 2', $this->capability, self::$base_slug, null, 'dashicons-lock'); // Create submenus foreach ($pages as $page) { if (!is_array($page)) { continue; } if (empty($page['link'])) { $menu_link = false; } else { $menu_link = $page['link']; } $slug = self::MENU_SLUG; if (!empty($page['slug'])) { $slug .= '-' . $page['slug']; } add_submenu_page(self::$base_slug, strip_tags($page['title']), $page['title'], $this->capability, $slug, array($this, 'handle_submenu_request')); /* * WordPress does not support absolute URLs in the admin-menu. * So we have to manny modify the menu-link href value if our slug * is an absolute URL. */ if ($menu_link) { $item = end($submenu[self::$base_slug]); $key = key($submenu[self::$base_slug]); $submenu[self::$base_slug][$key][2] = $menu_link; } } do_action('ms_controller_plugin_add_menu_pages', $this); // Setup the rest of the plugin after the menu was registered. do_action('ms_plugin_admin_setup'); }