/** * Re-order the submenu items so all Freemius added new submenu items * are added right after the plugin's settings submenu item. * * @author Vova Feldman (@svovaf) * @since 1.1.4 */ private function order_sub_submenu_items() { global $submenu; $menu_slug = $this->_menu->get_top_level_menu_slug(); /** * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us, * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission. * * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu * of another plugin, only users that have the right role can access its sub-submenus since we will use the * capability needed to access the parent menu as the capability for the submenus that we will add. */ if (empty($submenu[$menu_slug])) { return; } $top_level_menu =& $submenu[$menu_slug]; $all_submenu_items_after = array(); $found_submenu_item = false; foreach ($top_level_menu as $submenu_id => $meta) { if ($found_submenu_item) { // Remove all submenu items after the plugin's submenu item. $all_submenu_items_after[] = $meta; unset($top_level_menu[$submenu_id]); } if ($this->_menu->get_raw_slug() === $meta[2]) { // Found the submenu item, put all below. $found_submenu_item = true; continue; } } // Embed all plugin's new submenu items. $this->embed_submenu_items(); // Start with specially high number to make sure it's appended. $i = max(10000, max(array_keys($top_level_menu)) + 1); foreach ($all_submenu_items_after as $meta) { $top_level_menu[$i] = $meta; $i++; } // Sort submenu items. ksort($top_level_menu); }
/** * Re-order the submenu items so all Freemius added new submenu items * are added right after the plugin's settings submenu item. * * @author Vova Feldman (@svovaf) * @since 1.1.4 */ private function order_sub_submenu_items() { global $submenu; $top_level_menu =& $submenu[$this->_menu->get_top_level_menu_slug()]; $all_submenu_items_after = array(); $found_submenu_item = false; foreach ($top_level_menu as $submenu_id => $meta) { if ($found_submenu_item) { // Remove all submenu items after the plugin's submenu item. $all_submenu_items_after[] = $meta; unset($top_level_menu[$submenu_id]); } if ($this->_menu->get_raw_slug() === $meta[2]) { // Found the submenu item, put all below. $found_submenu_item = true; continue; } } // Embed all plugin's new submenu items. $this->embed_submenu_items(); // Start with specially high number to make sure it's appended. $i = 10000; foreach ($all_submenu_items_after as $meta) { $top_level_menu[$i] = $meta; $i++; } // Sort submenu items. ksort($top_level_menu); }
/** * Add default Freemius menu items. * * @author Vova Feldman (@svovaf) * @since 1.0.0 */ private function add_submenu_items() { $this->_logger->entrance(); $this->do_action('before_admin_menu_init'); if (!$this->is_addon()) { if ($this->is_registered() || $this->is_anonymous()) { if ($this->is_registered()) { // Add user account page. $this->add_submenu_item(__fs('account'), array(&$this, '_account_page_render'), $this->get_plugin_name() . ' – ' . __fs('account'), 'manage_options', 'account', array(&$this, '_account_page_load'), 10, $this->_menu->is_submenu_item_visible('account')); } // Add contact page. $this->add_submenu_item(__fs('contact-us'), array(&$this, '_contact_page_render'), $this->get_plugin_name() . ' – ' . __fs('contact-us'), 'manage_options', 'contact', array(&$this, '_clean_admin_content_section'), 10, $this->_menu->is_submenu_item_visible('contact')); if ($this->_has_addons()) { $this->add_submenu_item(__fs('add-ons'), array(&$this, '_addons_page_render'), $this->get_plugin_name() . ' – ' . __fs('add-ons'), 'manage_options', 'addons', array(&$this, '_addons_page_load'), WP_FS__LOWEST_PRIORITY - 1, $this->_menu->is_submenu_item_visible('addons')); } // Add upgrade/pricing page. $this->add_submenu_item($this->is_paying() ? __fs('pricing') : __fs('upgrade') . ' ➤', array(&$this, '_pricing_page_render'), $this->get_plugin_name() . ' – ' . __fs('pricing'), 'manage_options', 'pricing', array(&$this, '_clean_admin_content_section'), WP_FS__LOWEST_PRIORITY, $this->_menu->is_submenu_item_visible('pricing') && ($this->has_paid_plan() || isset($_GET['page']) && $this->_menu->get_slug('pricing') == $_GET['page'])); } } ksort($this->_menu_items); foreach ($this->_menu_items as $priority => $items) { foreach ($items as $item) { if (!isset($item['url'])) { $hook = add_submenu_page($item['show_submenu'] ? $this->is_addon() ? $this->get_parent_instance()->_menu->get_top_level_menu_slug() : $this->_menu->get_top_level_menu_slug() : null, $item['page_title'], $item['menu_title'], $item['capability'], $item['menu_slug'], $item['render_function']); if (false !== $item['before_render_function']) { add_action("load-{$hook}", $item['before_render_function']); } } else { add_submenu_page($this->is_addon() ? $this->get_parent_instance()->_menu->get_top_level_menu_slug() : $this->_menu->get_top_level_menu_slug(), $item['page_title'], $item['menu_title'], $item['capability'], $item['menu_slug'], array($this, '')); } } } }
/** * @author Vova Feldman (@svovaf) * @since 1.0.0 * * @return string */ private function get_top_level_menu_slug() { return $this->is_addon() ? $this->get_parent_instance()->_menu->get_top_level_menu_slug() : $this->_menu->get_top_level_menu_slug(); }
/** * Re-order the submenu items so all Freemius added new submenu items * are added right after the plugin's settings submenu item. * * @author Vova Feldman (@svovaf) * @since 1.1.4 */ private function order_sub_submenu_items() { global $submenu; $top_level_menu =& $submenu[$this->_menu->get_top_level_menu_slug()]; $all_submenu_items_after = array(); $found_submenu_item = false; foreach ($top_level_menu as $submenu_id => $meta) { if ($found_submenu_item) { // Remove all submenu items after the plugin's submenu item. $all_submenu_items_after[] = $meta; unset($top_level_menu[$submenu_id]); } if ($this->_menu->get_raw_slug() === $meta[2]) { // Found the submenu item, put all below. $found_submenu_item = true; continue; } } // Embed all plugin's new submenu items. $this->embed_submenu_items(); // FIX: Get highest array key value plus one foreach ($top_level_menu as $submenu_id => $meta) { $i = $submenu_id + 1; } foreach ($all_submenu_items_after as $meta) { $top_level_menu[$i] = $meta; $i++; } // Sort submenu items. ksort($top_level_menu); }