1

I can't display the submenu of my menu when creating a plugin (Beginner). Could you please help me to find my error? My plugin is well activated and the menu_page appears well

add_action('admin_menu','tictac_admin_menu_option');

function tictac_admin_menu_option()
{
  add_menu_page(
  'Gestion des Horaires',
  'Time Control',
  'manage_options',
  'tictac_admin_menu',
  'tictac_scripts_page',
  //plugins_url( 'time-control/admin/logo/tictac-logo.png' ),
  'dashicons-calendar-alt'
  //16
  );
  add_submenu_page('tictac_admin_menu',
  'Sous menu Opening',
  'Options Opening',
  'tictac_admin_submenu',
  'tictac_scripts_menu',
  'tictac_opening_submenu'
  );

}
function tictac_opening_submenu()
{
  ?>
  <div id="wrap">
    <h1>Add Opening</h1>
  </div>
  <?php
}

1 Answer 1

1

The fourth parameter in add_submenu_page function is a capability. Try changing it to manage_options so your code looks like this:

add_submenu_page('tictac_admin_menu',
  'Sous menu Opening',
  'Options Opening',
  'manage_options',
  'tictac_scripts_menu',
  'tictac_opening_submenu'

);

Hope it helps

2
  • Thanks it works. But i don't understand why i must choose "Manage_options". The codex does not explain very well
    – Rak Arthus
    Mar 25, 2018 at 13:06
  • You don't have to choose "manage_options" capability. I assumed you want this one, because you added it in the add_menu_page function. You have to pass any capability you want as the fourth parameter. You can find the list of available capabilities here: codex.wordpress.org/Roles_and_Capabilities "manage_options" is an administrator capability, so it means that only administrators will be able to access these pages
    – Raf
    Mar 26, 2018 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.