wp_admin_bar_my_account_menu

Add the "My Account" submenu items.

Description

wp_admin_bar_my_account_menu( (WP_Admin_Bar) $wp_admin_bar ); 

Parameters (1)

0. $wp_admin_bar (WP_Admin_Bar)
The wp admin bar.

Usage

  1. if ( !function_exists( 'wp_admin_bar_my_account_menu' ) ) { 
  2. require_once ABSPATH . WPINC . '/admin-bar.php'; 
  3.  
  4. // The wp admin bar. 
  5. $wp_admin_bar = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_admin_bar_my_account_menu($wp_admin_bar); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/admin-bar.php  
  1. function wp_admin_bar_my_account_menu( $wp_admin_bar ) { 
  2. $user_id = get_current_user_id(); 
  3. $current_user = wp_get_current_user(); 
  4.  
  5. if ( ! $user_id ) 
  6. return; 
  7.  
  8. if ( current_user_can( 'read' ) ) { 
  9. $profile_url = get_edit_profile_url( $user_id ); 
  10. } elseif ( is_multisite() ) { 
  11. $profile_url = get_dashboard_url( $user_id, 'profile.php' ); 
  12. } else { 
  13. $profile_url = false; 
  14.  
  15. $wp_admin_bar->add_group( array( 
  16. 'parent' => 'my-account',  
  17. 'id' => 'user-actions',  
  18. ) ); 
  19.  
  20. $user_info = get_avatar( $user_id, 64 ); 
  21. $user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; 
  22.  
  23. if ( $current_user->display_name !== $current_user->user_login ) 
  24. $user_info .= "<span class='username'>{$current_user->user_login}</span>"; 
  25.  
  26. $wp_admin_bar->add_menu( array( 
  27. 'parent' => 'user-actions',  
  28. 'id' => 'user-info',  
  29. 'title' => $user_info,  
  30. 'href' => $profile_url,  
  31. 'meta' => array( 
  32. 'tabindex' => -1,  
  33. ),  
  34. ) ); 
  35.  
  36. if ( false !== $profile_url ) { 
  37. $wp_admin_bar->add_menu( array( 
  38. 'parent' => 'user-actions',  
  39. 'id' => 'edit-profile',  
  40. 'title' => __( 'Edit My Profile' ),  
  41. 'href' => $profile_url,  
  42. ) ); 
  43.  
  44. $wp_admin_bar->add_menu( array( 
  45. 'parent' => 'user-actions',  
  46. 'id' => 'logout',  
  47. 'title' => __( 'Log Out' ),  
  48. 'href' => wp_logout_url(),  
  49. ) );