The menu SDK is available by calling the menu_page() method. The returned object offers a more readable, logical way of adding items to WordPress menus. Begin by generating the menu_page() object.

$menu_page = $this-menu_page();

You can use the $menu_page object or keep calling menu_page().

From there you can add a base menu. This is taken from the Broadcast WordPress plugin.

 ->callback_this( 'callback_method' )
 ->capability( 'edit_posts' )
 ->menu_slug( 'threewp_broadcast' )
 ->menu_title( __( 'Broadcast', 'threewp_broadcast' ) )
 ->page_title( __( 'Broadcast', 'threewp_broadcast' ) )
 ->icon_url( 'dashicons-rss' );

You can also add a submenu. These method calls are very similar to adding a whole menu. This is taken from the Broadcast Queue add-on.

 ->submenu( 'threewp_broadcast_queue' )
 ->callback_this( 'admin_menu_tabs' )
 ->menu_title( __( 'Queue', 'threewp_broadcast' ) )
 ->page_title( __( 'Broadcast Queue', 'threewp_broadcast' ) );

To commit your changes, you can either add everything to the menu.


Or just your submenus.


Why use only add_submenus? Sometimes you don’t want to create a whole menu item, but just add to an existing.

 ->menu_slug( 'options-general.php' );

 ->submenu( 'plainview_job_importer' )
 ->callback_this( 'admin_menu_tabs' )
 ->capability( 'manage_options' )
 ->menu_title( 'Job Importer' )
 ->page_title( 'Plainview Job Importer' );


If you want to start over, then treat the menu_page() object like the collection it is!


Leave a Reply

Your email address will not be published. Required fields are marked *