Is there a way to move a sub-menu item from one parent to another? I need to do it without any plugin.
I have following menu hierarchy in admin at the moment
Weather Alerts
- Weather Alerts
- Add NewWeather Settings
- Weather Settings
- Global Weather Settings
I have a user role named 'Weather Info Editor'. For users with this role I like the menu to come up like
Weather Alerts
- Global Weather Settings
- Weather Alerts
- Add New
and parent menu Weather Settings to disappear.
To get this done I tried the following but it does not work:
function remove_menu_pages_for_weather_info_editor() {
if(current_user_can('weather-info-editor')) {
remove_menu_page('tools.php');
remove_menu_page('options-general.php');
remove_menu_page('edit.php?post_type=seminar');
remove_menu_page('jetpack');
remove_menu_page( 'weather-settings');
}
}
add_action('admin_menu', 'remove_menu_pages_for_weather_info_editor', 999);
function move_global_settings_under_weather_alert() {
if(current_user_can('weather_info_editor')) {
add_submenu_page(
'edit.php?post_type=weather_alert',
'Global Weather Settings',
'Global Weather Settings',
'manage_options',
'global_weather_settings'
);
}
}
add_action('admin_menu', 'move_global_settings_under_weather_alert', 9);
I also tried 'weather_alert'
in place of 'edit.php?post_type=weather_alert',
in function move_global_settings_under_weather_alert
but that did not work either.
I am using this as reference.
Please suggest a way to accomplish the way.