wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_admin_bar_my_account_item › WordPress Function

Seit3.3.0
Veraltetn/v
wp_admin_bar_my_account_item ( $wp_admin_bar )
Parameter:
  • (WP_Admin_Bar) $wp_admin_bar The WP_Admin_Bar instance.
    Erforderlich: Ja
Definiert in:
Codex:

Adds the "My Account" item.



Quellcode

function wp_admin_bar_my_account_item( $wp_admin_bar ) {
	$user_id      = get_current_user_id();
	$current_user = wp_get_current_user();

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

	$avatar = get_avatar( $user_id, 26 );
	/* translators: %s: Current user's display name. */
	$howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' );
	$class = empty( $avatar ) ? '' : 'with-avatar';

	$wp_admin_bar->add_node(
		array(
			'id'     => 'my-account',
			'parent' => 'top-secondary',
			'title'  => $howdy . $avatar,
			'href'   => $profile_url,
			'meta'   => array(
				'class'      => $class,
				/* translators: %s: Current user's display name. */
				'menu_title' => sprintf( __( 'Howdy, %s' ), $current_user->display_name ),
				'tabindex'   => ( false !== $profile_url ) ? '' : 0,
			),
		)
	);
}