The add_menus() call doesn’t really add menus, it sets up callbacks to add menus. Thus you need to fire the action to cause the callbacks to run. Do so just before you call render().
do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
Note the ‘&’ before $wp_admin_bar. Your instance of WP_Admin_Bar must be passed by reference. No guarantees, untested, but explains your empty admin bar.
Thread Starter
psolaz
(@psolaz)
thanks bcworkz!
this is what i currently use
function admin_menu_test() {
// sleep(1);
/* Load the admin bar class code ready for instantiation */
require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
/* Instantiate the admin bar */
/**
* Filters the admin bar class to instantiate.
*/
$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
if ( class_exists( $admin_bar_class ) )
$wp_admin_bar = new $admin_bar_class;
else
return false;
$wp_admin_bar->initialize();
$wp_admin_bar->add_menus();
if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
return;
/**
* Load all necessary admin bar items.
*
* This is the hook used to add, remove, or manipulate admin bar items.
*/
do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
/**
* Fires before the admin bar is rendered.
*/
// do_action( 'wp_before_admin_bar_render' );
$wp_admin_bar->render();
// do_action ('wp_after_admin_bar_render');
}
add_action('wp_after_admin_bar_render' , 'admin_menu_test');
in the template i simply call admin_menu_test() .
Et voila a second admin bar is display as i wanted. However all the glorious extras added by plugins to the original adminbar is missing. shouldn’t it be added as well when firing the action or am i missing a point?
EDIT: for some reason it does not make any difference if i call $wp_adminbar->initalize() and ->add_menus() or not.
This is the whole mess of a plugin anyways if anyone stumbles upon this and tries to do the same thing: https://hastebin.com/iwuquqotas.xml
Thanks a lot for your help 🙂
-
This reply was modified 9 years, 1 month ago by
psolaz.
Thread Starter
psolaz
(@psolaz)
I am nearly there.
Couldn’t figure out how to create a second adminbar, however i just ‘moved’ the original one. Still some styling issues but this *should* work:
https://github.com/dreadkopp/wp_admin_bar_widget
-
This reply was modified 9 years, 1 month ago by
psolaz.