| 130 | * @since 3.3.0 |
| 131 | */ |
| 132 | function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
| 133 | $user_id = get_current_user_id(); |
| 134 | $current_user = wp_get_current_user(); |
| 135 | $profile_url = get_edit_profile_url( $user_id ); |
| 136 | |
| 137 | if ( ! $user_id ) |
| 138 | return; |
| 139 | |
| 140 | $avatar = get_avatar( $user_id, 28 ); |
| 141 | $howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name ); |
| 142 | $class = empty( $avatar ) ? '' : 'with-avatar'; |
| 143 | |
| 144 | $wp_admin_bar->add_menu( array( |
| 145 | 'id' => 'account', |
| 146 | 'parent' => 'top-secondary', |
| 147 | 'title' => $howdy . $avatar, |
| 148 | 'href' => $profile_url, |
| 149 | 'meta' => array( |
| 150 | 'class' => $class, |
| 151 | 'title' => __('My Account'), |
| 152 | ), |
| 153 | ) ); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Add the "My Account" submenu items. |
| 158 | * |
156 | | $user_info = get_avatar( $user_id, 64 ); |
157 | | $user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; |
158 | | |
159 | | if ( $current_user->display_name !== $current_user->user_nicename ) |
160 | | $user_info .= "<span class='username'>{$current_user->user_nicename}</span>"; |
161 | | |
162 | | $wp_admin_bar->add_menu( array( |
163 | | 'parent' => 'my-account', |
164 | | 'id' => 'user-info', |
165 | | 'title' => $user_info, |
166 | | 'href' => $profile_url, |
167 | | 'meta' => array( |
168 | | 'tabindex' => -1 |
169 | | ), |
170 | | ) ); |
171 | | $wp_admin_bar->add_menu( array( |
172 | | 'parent' => 'my-account', |
173 | | 'id' => 'edit-profile', |
174 | | 'title' => __( 'Edit My Profile' ), |
175 | | 'href' => $profile_url, |
176 | | ) ); |
177 | | $wp_admin_bar->add_menu( array( |
178 | | 'parent' => 'my-account', |
179 | | 'id' => 'logout', |
180 | | 'title' => __( 'Log Out' ), |
181 | | 'href' => wp_logout_url(), |
182 | | ) ); |
183 | | } |
| 175 | $wp_admin_bar->add_menu( array( |
| 176 | 'parent' => 'account', |
| 177 | 'id' => 'user-info', |
| 178 | 'title' => $user_info, |
| 179 | 'href' => $profile_url, |
| 180 | 'meta' => array( |
| 181 | 'tabindex' => -1, |
| 182 | ), |
| 183 | ) ); |
| 184 | $wp_admin_bar->add_menu( array( |
| 185 | 'parent' => 'account', |
| 186 | 'id' => 'edit-profile', |
| 187 | 'title' => __( 'Edit My Profile' ), |
| 188 | 'href' => $profile_url, |
| 189 | ) ); |
| 190 | $wp_admin_bar->add_menu( array( |
| 191 | 'parent' => 'account', |
| 192 | 'id' => 'logout', |
| 193 | 'title' => __( 'Log Out' ), |
| 194 | 'href' => wp_logout_url(), |
| 195 | ) ); |