• We will use action hook named 'admin_menu' to add custom menu items. Here is an example:
add_action('admin_menu', 'location_plugin_render');
• The function add_action('admin_menu', 'location_plugin_render'); is used to register a callback function called location_plugin_render to be executed when the admin menu is being created.
function location_plugin_render() {
// Menu Locations
add_menu_page(
__('Locations', 'manage-location'),
__('Locations', 'manage-location'),
'activate_plugins',
'fl-location',
'',
'dashicons-admin-users',
30
);
// Location Info
add_submenu_page(
'fl-appointment',
'All Locations',
'All Locations',
'view_location_capability',
'view-location',
'location_info_render_page'
);
// New Appointment
add_submenu_page(
'fl-location',
'Add New',
'Add New',
'add_location_capability',
'add-location',
'add_location_data_render_page'
);
// Edit Location
add_submenu_page(
'fl-location',
'Edit Location',
'Edit Location',
'edit_location_capability',
'edit-location',
'edit_location_data_render_page'
);
remove_submenu_page('fl-location', 'fl-location');
}
• If you want to hide the Edit Location or Add New submenu items from the Locations menu, you can simply remove fl-location the corresponding add_submenu_page function calls from your code.
// New Appointment
add_submenu_page(
'',
'Add New',
'',
'add_location_capability',
'add-location',
'add_location_data_render_page'
);
// Edit Location
add_submenu_page(
'',
'Edit Location',
'',
'edit_location_capability',
'edit-location',
'edit_location_data_render_page'
);
» Slugs:
» Capabilities: