Yoast's plug-in is actually a very good example if all you want to do is add menus. Basically, the admin bar is just an alternate set of links to the same plug-in admin pages you have in the sidebar. To add the top-level SEO menu, Yoast does the following:
$wp_admin_bar->add_menu( array( 'id' => 'wpseo-menu', 'title' => __( 'SEO' ), 'href' => get_admin_url('admin.php?page=wpseo_dashboard'), ) );
This adds a menu named "wpseo-menu" to the admin bar and directs users to the plug-in's dashboard when they click the link. Child links are added in a similar fashion:
$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __( 'Keyword Research' ), '#', ) );
You just specify the "parent" of the menu you're adding.
Then you can go as deep as you need to, calling
$wp_admin_bar->add_menu() when you need to and specifying the appropriate information.
For reference, the variable,
$wp_admin_bar is an instance of the class
WP_Admin_Bar() within WordPress. It has several different methods and properties, but the one you're most interested in here is, obviously,
add_menu(). This method accepts certain parameters:
- title - default false
- href - default false,
- parent - default false - pass the ID value for a submenu of that menu
- id - defaults to a sanitized title value.
- meta - default false - array of any of the following options:
array( 'html' => '', 'class' => '', 'onclick' => '', target => '' );
But the rest of the
WP_Admin_Bar() class is pluggable. It just depends on what exactly you're trying to do and how you want to do it.