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.

  'AdminPages' => array(
    'flakes' => array(

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

  $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 .'"));'

    'mvc_' . $controller . '-' . $method,
    array($dispatcher, $method)

add_action( 'admin_menu', 'my_modify_menu_pages' );

Michael #
Do you know how to change the main menu item's name without changing the actual model?
Prabhu Chelladurai #
In wordpress 4.0, the bootstrap file will be in 'yourplugin-name/app/config/bootstrap.php'
Prabhu Chelladurai #
could you please brief where to add this code exactly?
Janar #

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.
Prabhu Chelladurai #
Thanks for your immediate reply Janar. Very kind of you. Let me try some other resource or person. If you find any leisure time, please make it a point to help in this issue.

Thank you once again.
No gravatar aivable
2016bladeandsoul #
Take my word for it.
No gravatar aivable
leah melda #
It is important to identify the Admission Essay Writing Services that offers original and unique Essay Writer Services submitted on the Custom College Papers Online assignments.
I am co-founder of web/media studio GIVE me. and (android)developer at start-up named Choco. Read my about page to learn more.