bp_wp_admin_bar_my_account_menu( WP_Admin_Bar $wp_admin_bar )
Add the “My Account” submenu items.
Description
Parameters
- $wp_admin_bar
-
(Required)
Source
File: bp-core/bp-core-adminbar.php
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | function bp_wp_admin_bar_my_account_menu( $wp_admin_bar ) { $user_id = get_current_user_id(); $current_user = wp_get_current_user(); if ( ! $user_id ) { return ; } $display_name = $current_user ->data->display_name; $avatar = get_avatar( $user_id , 26 ); // my account $wp_admin_bar ->add_node( [ 'id' => 'my-account' , 'title' => '<span class="display-name">' . $display_name . $avatar . '</span>' ] ); // user info $user_info = get_avatar( $user_id , 64 ); $user_info .= "<span class='display-name'>" . $display_name . "</span>" ; $user_info .= "<span class='username'>" . bp_activity_get_user_mentionname( $user_id ) . "</span>" ; $wp_admin_bar ->add_menu([ 'id' => 'user-info' , 'title' => $user_info ]); if ( current_user_can( 'read' ) ) { $profile_url = get_edit_profile_url( $user_id ); } elseif ( is_multisite() ) { $profile_url = get_dashboard_url( $user_id , 'profile.php' ); } else { $profile_url = false; } $wp_admin_bar ->add_group( array ( 'parent' => 'my-account' , 'id' => 'user-actions' , ) ); $user_info = get_avatar( $user_id , 64 ); $user_info .= "<span class='display-name'>{$display_name}</span>" ; if ( $current_user ->display_name !== $current_user ->user_login ) { // Get the current display settings from BuddyBoss > Settings > Profiles > Display Name Format. $current_value = get_option( 'bp-display-name-format' ); if ( 'nickname' !== $current_value ) { $username = bp_activity_get_user_mentionname( $current_user ->ID ); if ( '' !== $username ) { $user_info .= "<span class='username'>{$username}</span>" ; } else { $user_info .= "<span class='username'>{$current_user->user_login}</span>" ; } } } $wp_admin_bar ->add_menu( array ( 'parent' => 'user-actions' , 'id' => 'user-info' , 'title' => $user_info , 'href' => $profile_url , 'meta' => array ( 'tabindex' => -1, ), ) ); if ( false !== $profile_url ) { $wp_admin_bar ->add_menu( array ( 'parent' => 'user-actions' , 'id' => 'edit-profile' , 'title' => __( 'Edit My Profile' , 'buddyboss' ), 'href' => $profile_url , ) ); } $wp_admin_bar ->add_menu( array ( 'parent' => 'user-actions' , 'id' => 'logout' , 'title' => __( 'Log Out' , 'buddyboss' ), 'href' => wp_logout_url(), ) ); } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.1.1 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.