Question

I know how to add custom menus and submenus for the custom plugin. But for creating another submenu under submenu is what I cannot figure out.

What I have:

Plugin-Main-Menu

  • Add
  • Update
  • Event

What I want:

Plugin-Main-Menu

  • Add
  • Update
  • Event

-Create Event(Should be under "Event" submenu ONLY)

-CheckOut Event(Should be under "Event" submenu ONLY)

I have defined the custom menu in the plugin-name.php in the root folder. I even tried adding the "Create Event"(it is inside separate folder and has filename create-event.php ) with "Event" as parent(event.php).

Here is my Plugin Folder Structure:

--inc

=>views

==>event.php(is /plugin-folder/inc/views/event.php)

==>create-event.php(is /plugin-folder/inc/views/create-event.php)

--js

--plugin-name.php

The php code I added in plugin-name.php

define("PLUGIN_DIR_PATH",plugin_dir_path(__FILE__));    
add_action( 'admin_menu', 'register_my_custom_menu_page' );
    function register_my_custom_menu_page() {
        add_menu_page(
            __( 'My Custom Plugin', 'textdomain' ),
            'MCP',
            'manage_options',
            '/plugin-folder/plugin-name.php',
            'home_pagefunc',
            'dashicons-tickets',
            6
        );
        add_submenu_page(
                '/plugin-folder/plugin-name.php',
                'Add',
                'Add',
                'manage_options',
                'add',
                'add_func',
                'dashicons-welcome-add-page'
            );
        add_submenu_page(
                '/plugin-folder/plugin-name.php',
                'Update',
                'Update',
                'manage_options',
                'update',
                'update_func',
                'dashicons-welcome-add-page'
            );
         add_submenu_page(
            '/plugin-folder/plugin-name.php',
            'Event',
            'Event',
            'manage_options',
            'event',
            'eventfunc',
            'dashicons-book'
        );
        add_submenu_page(
                '/plugin-folder/inc/views/event.php',
                'Create Event ',
                'Create Event',
                'manage_options',
                'create-event',
                'create_event_func',
                'dashicons-welcome-add-page'
        );
    }
    function home_pagefunc()
    {
     ?>
        <h1>MCP</h1>
    <?php
        }
        function add_func(){
        include_once PLUGIN_DIR_PATH."/inc/views/add.php";
        }

        function update_func(){
         include_once PLUGIN_DIR_PATH."/inc/views/update.php";
        }
        function event_func(){
         include_once PLUGIN_DIR_PATH."/inc/views/event.php";
        }
        function create_event_func(){
         include_once PLUGIN_DIR_PATH."/inc/views/create-event.php";
        }
    ?>

Should I be hooking the create event on the event.php? I just want the create-event.php to appear under event submenu. Please guide me as to where am I going wrong as I have just begun Wordpress Plugin Development. Any help is appreciated.

Était-ce utile?

La solution

Third level in admin menu items is not possible, see this answer.

However some plugins use imitation of third level menu. Use css to add left margin/padding to your sub-sub-items to make them look as third level menu.

BTW, last parameter of add_submenu_page must bet position, not icon name. Reed function docs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top