/** * Prepare a menu item to be converted to the WordPress format and added to the current * WordPress admin menu. This function applies menu defaults and templates, calls filters * that allow other components to tweak the menu, decides on what capability/-ies to use, * and so on. * * Caution: The filters called by this function may cause side-effects. Specifically, the Pro-only feature * for displaying menu pages in a frame does this. See wsMenuEditorExtras::create_framed_menu(). * Therefore, it is not safe to call this function more than once for the same item. * * @param array $item Menu item in the internal format. * @param string $item_type Either 'menu' or 'submenu'. * @param string $parent Optional. The parent of this sub-menu item. An empty string for top-level menus. * @return array Menu item in the internal format. */ private function prepare_for_output($item, $item_type = 'menu', $parent = '') { // Special case : plugin pages that have been moved from a sub-menu to a different // menu or the top level. We'll need to adjust the file field to point to the correct URL. // This is required because WP identifies plugin pages using *both* the plugin file // and the parent file. if ($item['template_id'] !== '' && !$item['separator']) { $template = $this->item_templates[$item['template_id']]; if ($template['defaults']['is_plugin_page']) { $default_parent = $template['defaults']['parent']; if ($parent != $default_parent) { $item['file'] = $template['defaults']['url']; } } } //Apply defaults & filters $item = ameMenuItem::apply_defaults($item); $item = ameMenuItem::apply_filters($item, $item_type, $parent); //may cause side-effects $item['access_level'] = $this->get_menu_capability($item); $this->add_access_lookup($item, $item['access_level'], $item_type); //Used later to determine the current page based on URL. $item['url'] = ameMenuItem::generate_url($item['file'], $parent); //Convert relative URls to fully qualified ones. This prevents problems with WordPress //incorrectly converting "index.php?page=xyz" to, say, "tools.php?page=index.php?page=xyz" //if the menu item was moved from "Dashboard" to "Tools". $itemFile = ameMenuItem::remove_query_from($item['file']); $shouldMakeAbsolute = strpos($item['file'], '://') === false && substr($item['file'], 0, 1) != '/' && $itemFile == 'index.php' && strpos($item['file'], '?') !== false; if ($shouldMakeAbsolute) { $item['file'] = admin_url($item['url']); } return $item; }
/** * Prepare a menu item to be converted to the WordPress format and added to the current * WordPress admin menu. This function applies menu defaults and templates, calls filters * that allow other components to tweak the menu, decides on what capability/-ies to use, * and so on. * * Caution: The filters called by this function may cause side-effects. Specifically, the Pro-only feature * for displaying menu pages in a frame does this. See wsMenuEditorExtras::create_framed_menu(). * Therefore, it is not safe to call this function more than once for the same item. * * @param array $item Menu item in the internal format. * @param string $item_type Either 'menu' or 'submenu'. * @param string $parent Optional. The parent of this sub-menu item. An empty string for top-level menus. * @return array Menu item in the internal format. */ private function prepare_for_output($item, $item_type = 'menu', $parent = '') { // Special case : plugin pages that have been moved from a sub-menu to a different // menu or the top level. We'll need to adjust the file field to point to the correct URL. // This is required because WP identifies plugin pages using *both* the plugin file // and the parent file. if ($item['template_id'] !== '' && !$item['separator']) { $template = $this->item_templates[$item['template_id']]; if ($template['defaults']['is_plugin_page']) { $default_parent = $template['defaults']['parent']; if ($parent != $default_parent) { $item['file'] = $template['defaults']['url']; } } } //Give each unclickable item a unique URL. if ($item['template_id'] === ameMenuItem::unclickableTemplateId) { static $unclickableCounter = 0; $unclickableCounter++; $unclickableUrl = '#' . ameMenuItem::unclickableTemplateClass . '-' . $unclickableCounter; $item['file'] = $item['url'] = $unclickableUrl; //The item must have the special "unclickable" class even if the user overrides the class. $cssClass = ameMenuItem::get($item, 'css_class', ''); if (strpos($cssClass, ameMenuItem::unclickableTemplateClass) === false) { $item['css_class'] = ameMenuItem::unclickableTemplateClass . ' ' . $cssClass; } } //Menus that have both a custom icon URL and a "menu-icon-*" class will get two overlapping icons. //Fix this by automatically removing the class. The user can set a custom class attr. to override. $hasCustomIconUrl = !ameMenuItem::is_default($item, 'icon_url'); $hasIcon = !in_array(ameMenuItem::get($item, 'icon_url'), array('', 'none', 'div')); if (ameMenuItem::is_default($item, 'css_class') && $hasCustomIconUrl && $hasIcon) { $new_classes = preg_replace('@\\bmenu-icon-[^\\s]+\\b@', '', $item['defaults']['css_class']); if ($new_classes !== $item['defaults']['css_class']) { $item['css_class'] = $new_classes; } } //Apply defaults & filters $item = ameMenuItem::apply_defaults($item); $item = ameMenuItem::apply_filters($item, $item_type, $parent); //may cause side-effects $item = $this->set_final_menu_capability($item); if (!$this->options['security_logging_enabled']) { unset($item['access_check_log']); //Throw away the log to conserve memory. } $this->add_access_lookup($item, $item_type); //Menus without a custom icon image should have it set to "none" (or "div" in older WP versions). //See /wp-admin/menu-header.php for details on how this works. if ($item['icon_url'] === '') { $item['icon_url'] = 'none'; } //Submenus must not have the "menu-top" class(-es). In WP versions that support submenu CSS classes, //it can break menu display. if (!empty($item['css_class']) && $item_type === 'submenu') { $item['css_class'] = preg_replace('@\\bmenu-top(?:-[\\w\\-]+)?\\b@', '', $item['css_class']); } elseif ($item_type === 'menu' && !$item['separator'] && !preg_match('@\\bmenu-top\\b@', $item['css_class'])) { //Top-level menus should always have the "menu-top" class. $item['css_class'] = 'menu-top ' . $item['css_class']; } //Add submenu icons if necessary. if ($item_type === 'submenu' && $hasIcon) { $item = apply_filters('admin_menu_editor-submenu_with_icon', $item, $hasCustomIconUrl); } //Used later to determine the current page based on URL. if (empty($item['url'])) { $original_parent = !empty($item['defaults']['parent']) ? $item['defaults']['parent'] : $parent; $item['url'] = ameMenuItem::generate_url($item['file'], $original_parent); } //Convert relative URls to fully qualified ones. This prevents problems with WordPress //incorrectly converting "index.php?page=xyz" to, say, "tools.php?page=index.php?page=xyz" //if the menu item was moved from "Dashboard" to "Tools". $itemFile = ameMenuItem::remove_query_from($item['file']); $shouldMakeAbsolute = strpos($item['file'], '://') === false && substr($item['file'], 0, 1) != '/' && $itemFile == 'index.php' && strpos($item['file'], '?') !== false; if ($shouldMakeAbsolute) { $item['file'] = admin_url($item['url']); } //WPML support: Use translated menu titles where available. if (!$item['separator'] && function_exists('icl_t')) { $item['menu_title'] = icl_t(self::WPML_CONTEXT, $this->get_wpml_name_for($item, 'menu_title'), $item['menu_title']); } return $item; }
/** * Prepare a menu item to be converted to the WordPress format and added to the current * WordPress admin menu. This function applies menu defaults and templates, calls filters * that allow other components to tweak the menu, decides on what capability/-ies to use, * and so on. * * Caution: The filters called by this function may cause side-effects. Specifically, the Pro-only feature * for displaying menu pages in a frame does this. See wsMenuEditorExtras::create_framed_menu(). * Therefore, it is not safe to call this function more than once for the same item. * * @param array $item Menu item in the internal format. * @param string $item_type Either 'menu' or 'submenu'. * @param string $parent Optional. The parent of this sub-menu item. An empty string for top-level menus. * @return array Menu item in the internal format. */ private function prepare_for_output($item, $item_type = 'menu', $parent = '') { // Special case : plugin pages that have been moved from a sub-menu to a different // menu or the top level. We'll need to adjust the file field to point to the correct URL. // This is required because WP identifies plugin pages using *both* the plugin file // and the parent file. if ($item['template_id'] !== '' && !$item['separator']) { $template = $this->item_templates[$item['template_id']]; if ($template['defaults']['is_plugin_page']) { $default_parent = $template['defaults']['parent']; if ($parent != $default_parent) { $item['file'] = $template['defaults']['url']; } } } //Apply defaults & filters $item = ameMenuItem::apply_defaults($item); $item = ameMenuItem::apply_filters($item, $item_type, $parent); //may cause side-effects //Check if the current user can access this menu. $user_has_access = true; $cap_to_use = ''; if (!empty($item['access_level'])) { $user_has_access = $user_has_access && $this->current_user_can($item['access_level']); $cap_to_use = $item['access_level']; } if (!empty($item['extra_capability'])) { $user_has_access = $user_has_access && $this->current_user_can($item['extra_capability']); $cap_to_use = $item['extra_capability']; } $item['access_level'] = $user_has_access ? $cap_to_use : 'do_not_allow'; //Used later to determine the current page based on URL. $item['url'] = ameMenuItem::generate_url($item['file'], $parent); return $item; }