pcwriter

Messing with the toolbar

Jun 11th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. /*Add custom links to adminbar My Account menu. Also remove default Logout and add repositioned Logout under all else.*/
  2. add_action( 'admin_bar_menu', 'toolbar_prep_link', 1 );
  3. add_action( 'admin_bar_menu', 'toolbar_journal_link', 2 );
  4. add_action( 'admin_bar_menu', 'toolbar_logout_link', 3 );
  5. add_action( 'admin_bar_menu', 'remove_default_logout', 999 );
  6. add_action( 'admin_bar_menu', 'remove_default_edit_profile', 999 );
  7. add_action( 'admin_bar_menu', 'custom_admin_bar_profile_links', 80 );
  8.  
  9. function remove_default_logout( $wp_admin_bar ) {
  10. $wp_admin_bar->remove_node( 'logout' );
  11. }
  12. function remove_default_edit_profile( $wp_admin_bar ) {
  13. $wp_admin_bar->remove_node( 'edit-profile' );
  14. }
  15. function toolbar_prep_link( $wp_admin_bar ) {
  16. $args = array(
  17. 'id' => 'my_prep',
  18. 'title' => 'My PReP',
  19. 'href' => bp_loggedin_user_domain() . 'prep',
  20. 'parent' => 'user-actions',
  21. );
  22. $wp_admin_bar->add_node( $args );
  23. }
  24. function toolbar_journal_link( $wp_admin_bar ) {
  25. global $current_user;
  26. $userID = bp_loggedin_user_id();
  27. $user_blogs = get_blogs_of_user( $userID );
  28.  
  29. foreach ( $user_blogs as $user_blog ) {
  30. if ( $user_blog->userblog_id != 1 ) {
  31. if ( !isset( $journalsite ) ) {
  32. $journalsite = $user_blog->userblog_id;
  33. $args = array(
  34. 'id' => 'my_journal',
  35. 'title' => 'My Journal',
  36. 'parent' => 'user-actions',
  37. 'href' => $user_blog->path,
  38. );
  39. }
  40. }
  41. }
  42. $wp_admin_bar->add_node( $args );
  43. }
  44. function toolbar_logout_link( $wp_admin_bar ) {
  45. $args = array(
  46. 'id' => 'my_logout',
  47. 'title' => 'Network Logout',
  48. 'href' => wp_logout_url(),
  49. 'parent' => 'user-actions',
  50. );
  51. $wp_admin_bar->add_node( $args );
  52. }
  53.  
  54. function custom_admin_bar_profile_links( $wp_admin_bar ) {
  55. //from http://wordpress.stackexchange.com/questions/47824/modify-admin-bar-link?rq=1
  56. $new_content_node = $wp_admin_bar->get_node('my-account');
  57. $new_content_node->href = bp_loggedin_user_domain();
  58. $wp_admin_bar->add_node($new_content_node);
  59.  
  60. $userID = bp_loggedin_user_id();
  61. $user_info = get_avatar( $userID, 64 );
  62.  
  63. $new_content_node2 = $wp_admin_bar->get_node('user-info');
  64. $new_content_node2->href = bp_loggedin_user_domain();
  65. $new_content_node2->title = $user_info;
  66. $wp_admin_bar->add_node($new_content_node2);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment