Add a page to the main menu block: add_object_page
This short post documents a menu hook that’s not in the official Wordpress Codex.
As you might know, plugins developer have use the add(_something)_page family of functions to hook up their own pages to the existing Wordpress Menu.
This one will come in handy to those who need their plugin to be prominent.
add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '')
This function is in `wp-admin/includes/plugin.php.
add_object_page list your page in the main block, after “Comments”.
Of course think twice before using it. As the name suggests, just “objects” are supposed to go in this area of the menu. I would define objects as entities, models in the MVC paradigm. Objects are basically the “content, the ‘c’ of a CMS.
In my case, I am going to add here my Events. If you think about it it makes sense, a user manages his posts, media, links, pages, comments and events.

As you see, I’ve added a number of submenu items to this menu. This is the way you do it:
add_object_page(__('Events', 'dbem'),__('Events', 'dbem'),MIN_CAPABILITY,__FILE__, dbem_events_subpanel); add_submenu_page(__FILE__, __('Add new'), __('Add new'), MIN_CAPABILITY, 'new_event', "dbem_new_event_page"); add_submenu_page(__FILE__, "Venues", "Venues", MIN_CAPABILITY, 'venues', "dbem_venues_page"); add_submenu_page(__FILE__, "People", "People", MIN_CAPABILITY, 'people', "dbem_people_page");
__FILE__ identify my object page; the “Add New” submenu page references the same __FILE__ element. This way Wordpress knows he has to attach this second new page to the first one. The same applies to the “Venue” and “People” pages.
The clog icon that you see is the Wordpress predefined one for new “top level” pages. As the function header shows, you can easily add your own icon; this is a nice touch from the Wordpress development team.
By the way, this is the first glimpse of Events Manager 2.0; more to come, quite soon.







Leave a Reply