/** * Register admin menu for IT Contactform Plugin. * * @return void */ public static function wr_contactform_register_menus() { global $pagenow; // Get product information $plugin = WR_CF_Product_Info::get(WR_CONTACTFORM_IDENTIFICATION); // Generate menu title $menu_title = __('WR ContactForm', WR_CONTACTFORM_TEXTDOMAIN); if (isset($plugin['Available_Update']) && ('edit.php' != $pagenow || !isset($_GET['post_type']) || !in_array($_GET['post_type'], self::$pages))) { WR_CF_Init_Admin_Menu::replace('WR ContactForm', array(0 => "WR ContactForm <span class='wr-available-updates update-plugins count-{$plugin['Available_Update']}'><span class='pending-count'>{$plugin['Available_Update']}</span></span>", 1 => 'edit_posts', 2 => 'edit.php?post_type=wr_cf_post_type', 3 => '', 4 => 'menu-top menu-icon-wr_cf_post_type', 5 => 'menu-posts-wr_cf_post_type', 6 => WR_CONTACTFORM_URI . '/assets/images/icons-16/icon-forms.png')); } // Register menu item for Forms page WR_CF_Init_Admin_Menu::add(array('parent_slug' => 'edit.php?post_type=wr_cf_post_type', 'menu_title' => __('All Forms', WR_CONTACTFORM_TEXTDOMAIN), 'page_title' => __('All Forms', WR_CONTACTFORM_TEXTDOMAIN), 'menu_slug' => 'edit.php?post_type=wr_cf_post_type', 'capability' => 'edit_posts', 'menu_slug' => 'edit.php?post_type=wr_cf_post_type')); // Register menu item for Forms page WR_CF_Init_Admin_Menu::add(array('parent_slug' => 'edit.php?post_type=wr_cf_post_type', 'menu_title' => __('Add New', WR_CONTACTFORM_TEXTDOMAIN), 'page_title' => __('Add New', WR_CONTACTFORM_TEXTDOMAIN), 'menu_slug' => 'post-new.php?post_type=wr_cf_post_type', 'capability' => 'edit_posts', 'menu_slug' => 'post-new.php?post_type=wr_cf_post_type')); // Register menu item for Submissions page WR_CF_Init_Admin_Menu::add(array('parent_slug' => 'edit.php?post_type=' . 'wr_cf_post_type', 'page_title' => 'WR ContactForm Plugin - Submissions', 'menu_title' => 'Submissions', 'capability' => 'edit_posts', 'menu_slug' => 'edit.php?post_type=wr_cfsb_post_type')); // Register menu item for configuration page WR_CF_Init_Admin_Menu::add(array('parent_slug' => 'edit.php?post_type=' . 'wr_cf_post_type', 'page_title' => 'WR ContactForm Plugin - Settings', 'menu_title' => 'Settings', 'capability' => 'edit_posts', 'menu_slug' => 'wr-contactform-settings', 'function' => array('WR_Contactform_Helpers_Hook', 'settings'))); if ($plugin['Addons']) { // Generate menu title $menu_title = __('Add-ons', WR_CONTACTFORM_TEXTDOMAIN); if ($plugin['Available_Update'] && ('edit.php' == $pagenow && isset($_GET['post_type']) && in_array($_GET['post_type'], self::$pages))) { $menu_title .= " <span class='wr-available-updates update-plugins count-{$plugin['Available_Update']}'><span class='pending-count'>{$plugin['Available_Update']}</span></span>"; } // Register menu item for configuration page WR_CF_Init_Admin_Menu::add(array('parent_slug' => 'edit.php?post_type=' . 'wr_cf_post_type', 'page_title' => 'WR ContactForm Plugin - Addons', 'menu_title' => $menu_title, 'capability' => 'edit_posts', 'menu_slug' => 'wr-contactform-addons', 'function' => array('WR_Contactform_Helpers_Hook', 'addons'))); } WR_CF_Init_Admin_Menu::add(array('parent_slug' => 'edit.php?post_type=' . 'wr_cf_post_type', 'page_title' => 'WR ContactForm Plugin - About', 'menu_title' => 'About', 'capability' => 'edit_posts', 'menu_slug' => 'wr-contactform-about-us', 'function' => array('WR_Contactform_Helpers_Hook', 'about'))); }
/** * Manipulate WordPress admin menu. * * @return void */ public static function admin_menu() { global $menu, $submenu; // Filter menus to be registered self::$add = apply_filters('wr_cf_register_admin_menu', self::$add); // Variable to hold menu position static $position; // Add menus foreach (self::$add as $entry) { if (isset($entry['parent_slug'])) { add_submenu_page($entry['parent_slug'], $entry['page_title'], $entry['menu_title'], $entry['capability'], $entry['menu_slug'], isset($entry['function']) ? $entry['function'] : ''); } else { // Calculate menu position if (!isset($entry['position']) || empty($entry['position'])) { if (!isset($position)) { eval('$position = 50.' . rand(100, 1000) . ';'); } else { $position++; } } add_menu_page($entry['page_title'], $entry['menu_title'], $entry['capability'], $entry['menu_slug'], isset($entry['function']) && !empty($entry['function']) ? $entry['function'] : '', isset($entry['icon_url']) && !empty($entry['icon_url']) ? $entry['icon_url'] : '', isset($entry['position']) && !empty($entry['position']) ? "{$entry['position']}" : "{$position}"); } } // Remove menus foreach (self::$remove as $menu_slug => $parent_slug) { if ($parent_slug) { remove_submenu_page($parent_slug, $menu_slug); } else { remove_menu_page($menu_slug); } } // Replace menus if (count(self::$replace)) { foreach (self::$replace as $label => $data) { // Get parent slug $parent_slug = array_keys($data); $parent_slug = array_shift($parent_slug); if ($parent_slug && isset($submenu[$parent_slug])) { foreach ($submenu[$parent_slug] as $key => $value) { if ($value[0] === $label) { foreach ($data[$parent_slug] as $k => $v) { $submenu[$parent_slug][$key][$k] = $v; } } } } elseif ($parent_slug === 0) { foreach ($menu as $key => $value) { if ($value[0] === $label) { foreach ($data[0] as $k => $v) { $menu[$key][$k] = $v; } } } } } } }