wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_admin_bar_my_account_item › WordPress Function

Since3.3.0
Deprecatedn/a
› wp_admin_bar_my_account_item ( $wp_admin_bar )
Parameters:
  • (WP_Admin_Bar) $wp_admin_bar The WP_Admin_Bar instance.
    Required: Yes
Defined at:
Codex:
Change Log:
  • 7.2.0

Adds the "My Account" item.



Source

function wp_admin_bar_my_account_item( $wp_admin_bar ) {
	$user_id = get_current_user_id();
	if ( ! $user_id ) {
		return;
	}

	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;
	}

	$current_user = wp_get_current_user();
	$display_name = $current_user->display_name;
	if ( empty( $display_name ) ) {
		$display_name = $current_user->user_login;
	}

	$avatar = get_avatar( $user_id, 28 );
	$wp_admin_bar->add_node(
		array(
			'id'     => 'my-account',
			'parent' => 'top-secondary',
			'title'  => '<span class="display-name">' . $display_name . '</span>' . $avatar,
			'href'   => $profile_url,
			'meta'   => array(
				'class'      => empty( $avatar ) ? '' : 'with-avatar',
				'menu_title' => wp_strip_all_tags( $display_name ),
				'tabindex'   => ( false !== $profile_url ) ? '' : 0,
			),
		)
	);
}