Admin submenu does not call function to load the page



I’m making a big plugin with a complex architecture. I would like in my plugin architecture split pages and menus building on admin side.

So I have these classes : Menu.php, Submenu.php and Page.php, SubPage.php

I would like, when the administrator clik on menu/submenu links, it runs a common function callback inside Menu.php and Submenu.php which load only the right page or subpage thanks $_GET['page'].


Each submenu link does not bind a subpage anymore.

All href of submenu links are in this format :

instead of :


class SubMenu { 

    public $parent_slug;

    public $page_title;

    public $menu_title;

    public $capability;

    public $menu_slug;

    public $priority;

   public function __construct( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $priority = 10 ) {
       $this->parent_slug = $parent_slug;
       $this->page_title = $page_title;
       $this->menu_title = $menu_title;
       $this->capability = $capability;
       $this->menu_slug = $menu_slug;
       $this->priority = $priority;

       // Initialize the component
       add_action( 'admin_menu', array( $this, 'add_submenu' ), $this->priority );

   public function add_submenu() {

        $page_hook = add_submenu_page(
             _x( $this->page_title, "page_title", PLUGIN_DOMAIN ), 
             _x( $this->menu_title, "menu_title", PLUGIN_DOMAIN ), 
             array( $this, "output_rooter" ) 


   public function output_rooter(){
        // check $_GET['page'] value
        // Load the right SubPage class with the view
        $class = strToKamelCase( $_GET['page'] );
        new $class(); //<-- extends SubPage.php


The function output_rooter is never called and I have a 404 error each time I click on a submenu link.

Notice : with menu links it works correctly and all href links are perfect.

Someone has got an idea what it should be ?

, J.BizMai 5 years 2018-02-15T08:47:16-05:00 0 Answers 57 views 0

Leave an answer