[Plugin: WP MVC] Custom admin menu / using one top level menu per plugin
-
Hi there,
I’m trying to generate the menu by myself since I want to use one top level menu per plugin instead of one per controller.
So I went through the add_menu_pages() function in wp-mvc\core\loaders\mvc_admin_loader.php and for what I understand I need to add an handling method to the dispatcher doing something like that:
$this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$admin_controller_name.'", "action" => "index"));');
So my problem is how can I get the current instance of the loader class to access the dispatcher attribute?
Here is the function I’ve drafted so far:
function create_mvc_admin_menu($controllers) { if (!is_array($controllers) || count($controllers) == 0) return; $menu_position = 20; $menu_position = apply_filters('mvc_menu_position', $menu_position); $main_controller = array_shift($controllers); $controller_titleized = MvcInflector::titleize($main_controller); $admin_controller_name = 'admin_'.$main_controller; $top_level_handle = 'mvc_'.$main_controller; $method = $admin_controller_name.'_index'; // /!\ This will fail since there is no $this $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$admin_controller_name.'", "action" => "index"));'); add_menu_page( $controller_titleized, $controller_titleized, 'administrator', $top_level_handle, array($this->dispatcher, $method), null, $menu_position ); foreach ($controllers as $controller) { $method = $controller.'_index'; $page_handle = $top_level_handle.'-'.$controller; if (!method_exists($this->dispatcher, $method)) { $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller.'", "action" => "list"));'); } add_submenu_page( $top_level_handle, $controller_titleized.' ? '.MvcInflector::titleize($controller), MvcInflector::titleize($controller), 'administrator', $page_handle, array($this->dispatcher, $method) ); } }
Any suggestions? Thanks!
- The topic ‘[Plugin: WP MVC] Custom admin menu / using one top level menu per plugin’ is closed to new replies.