wp_admin_bar_my_account_item

Add the "My Account" item.

Description

wp_admin_bar_my_account_item( (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_item' ) ) { 
  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_item($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_item( $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. $avatar = get_avatar( $user_id, 26 ); 
  16. /** translators: %s: current user's display name */ 
  17. $howdy = sprintf( __( 'Howdy, %s' ), $current_user->display_name ); 
  18. $class = empty( $avatar ) ? '' : 'with-avatar'; 
  19.  
  20. $wp_admin_bar->add_menu( array( 
  21. 'id' => 'my-account',  
  22. 'parent' => 'top-secondary',  
  23. 'title' => $howdy . $avatar,  
  24. 'href' => $profile_url,  
  25. 'meta' => array( 
  26. 'class' => $class,  
  27. ),  
  28. ) );