function wpcf_custom_types_menu_order_set($menu) { $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array()); if (!empty($custom_types)) { foreach ($custom_types as $post_type => $data) { if (empty($data) || !isset($data['menu_position']) || strpos($data['menu_position'], '--wpcf-add-menu-after--') === false) { continue; } // at this point we have not only an integer as menu position $menu_position = explode('--wpcf-add-menu-after--', $data['menu_position']); if (!isset($menu_position[1]) || empty($menu_position[1])) { continue; } $current_index = array_search('edit.php?post_type=' . $data['slug'], $menu); // remove all items of $menu which are not matching selected menu $menu_filtered = array_keys($menu, $menu_position[1]); // use last match for resorting // https://onthegosystems.myjetbrains.com/youtrack/issue/types-591 $add_menu_after_index = array_pop($menu_filtered); // if both found resort menu if ($current_index && $add_menu_after_index) { wpcf_custom_types_menu_order_move($menu, $current_index, $add_menu_after_index); } } } return $menu; }
/** * @param $menu * @param $data * @param $menu_position * * @return mixed */ function types_menu_order_item_sort(&$menu, $current_url, $target_url) { // current index $current_index = array_search($current_url, $menu); // remove all items of $menu which are not matching selected menu $menu_filtered = array_keys($menu, $target_url); // use last match for resorting // https://onthegosystems.myjetbrains.com/youtrack/issue/types-591 $add_menu_after_index = array_pop($menu_filtered); // if both found resort menu if ($current_index && $add_menu_after_index) { wpcf_custom_types_menu_order_move($menu, $current_index, $add_menu_after_index); } return $menu; }