• Hi,

    i have created a WordPress-Plugin and now I am solving some open issues. I have used “DX Plugin Base” as base for my plugin.

    My plugin has ist own menu in wordpress-backend.
    It is working, but I think I didn’t make it right.
    Please find below the relevant code I use for my admin-menu:

    class myplugin_Plugin_Base {
    
      function __construct() {
    
        // register admin pages for the plugin
        add_action( 'admin_menu', array( $this, 'myplugin_admin_pages_callback' ) );
    
      }
    
      // Menüpunkte im WordPress-Backend bzw. Dashboard registrieren
      function myplugin_admin_pages_callback() {
        add_menu_page(__( "myplugin", 'myplugin' ), __( "myplugin", 'myplugin' ), 'edit_themes', 'myplugin_setup', array( $this, 'myplugin_setup' ), 'dashicons-cart' );
      }
    
      function myplugin_setup() {
          include_once( myplugin_PATH . '/myplugin-backend.php' );
      }
    
    }

    I only want to have ONE single menu-item.
    I have read somewhere, that I have to create a top-level-menu, like I did with the code above.
    Also I would have to create a sub-level-menu item?

    I don’t know. Could anybody help me with it?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You can have one or the other or both, it depends on where you want the menu item to appear in the menu. If always visible along with Posts, Appearance, etc. then you want a top level menu with add_menu_page(). If you want it to appear when an existing top level menu opens, say “Tools”, then you want a submenu with add_submenu_page(). Be sure to specify the correct top menu slug that you want your submenu to appear under. See Administration_Menus – Sub-Level_Menus for the default menu slugs.

    For anyone with more than one menu, you can do any combination you can imagine, top-top, top-sub, sub-sub, sub-subsub, etc. The top level can also be repeated as a sub with a different label, as is done for most WP menus, or the same label, or not repeated, your choice.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding admin-menu for plugin’ is closed to new replies.