Customizing admin menus which are created by Wordpress MVC plugin
At the Time of writing this article, WP-MVC plugin was at its version 1.2
Wordpress MCV seems to be pretty cool plugin but I immediately ran into some menu related issues when started using it. I'll explain what are these problems and how I fixed them.
Default menu layout
At first let me show what MVC does by default. It creates one top level menu per controller and adds "Add new" action into it's submenu. Lets suppose my controller's name is "flakes". Following image explains how it would look like.
Adding actions
If you want to add more actions you need to configure your plugin to do that. Start by creating file in your plugin's folder named "bootstrap.php" in folder "yourplugin_name/config/". Also create action in admin controller named "other1" - otherwise this menu item will not be rendered. Tip: by removing "add" item from config it dissappears from menu also.
MvcConfiguration::append(array( 'AdminPages' => array( 'flakes' => array( 'add', 'other1', ), ) ));
Adding actions from other controllers
By default MVC creates one top menu item for each controller. But what if you need to add actions from other controllers into one top level menu? It's actually pretty easy to achieve. We can use some WP built in menu functions to do it. In example below I will add "manage" action from "things" controller into our "flakes" top menu item. This code can be added into some plugin's source or into theme's functions.php file. Hopefully the code is fairly self-explanatory.
function my_modify_menu_pages() { //remove original automatically created top menu item remove_menu_page('mvc_things'); $controller = 'things'; //other controllers name $action = 'manage'; //action name $class = 'admin_' . $controller; $method = $controller . '_' . $action; //get MVC dispatcher $dispatcher = new MvcDispatcher(); if (!method_exists($dispatcher, $method)) { $dispatcher->{$method} = create_function( '', 'MvcDispatcher::dispatch(array("controller" => "' . $class . '", "action" => "' . $action .'"));' ); } add_submenu_page( 'mvc_flakes', 'Things', 'Things', 'administrator', 'mvc_' . $controller . '-' . $method, array($dispatcher, $method) ); } add_action( 'admin_menu', 'my_modify_menu_pages' );
Categories:
Wordpress
- Programming
Id dont't understand. "my_modify_menu_pages" maybe into functions.php in your theme. Also probably can add it into MCV plugin bootsrap file also.
Really can't remember @ last.
anyway - seems that this MCV framework is not updated a long time- does it work at all these days? I suppose it works hence you are asking questions here.
But I'am not able to help you with it much today.
Thank you once again.
:)
2016bladeandsoul https://2016bladeandsoul.wordpress.com