wp_admin_bar_my_account_menu() - WordPress 函数参考中文文档

返回介绍

wp_admin_bar_my_account_menu()

发布于 2017-09-11 字数2904 浏览 855 评论 0

wp_admin_bar_my_account_menu( WP_Admin_Bar $wp_admin_bar )

Add the “My Account” submenu items.


描述


参数

$wp_admin_bar

(WP_Admin_Bar)
(Required)


源代码

File: wp-includes/admin-bar.php

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

	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'>{$current_user->display_name}</span>";

	if ( $current_user->display_name !== $current_user->user_login )
		$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' ),
			'href'   => $profile_url,
		) );
	}

	$wp_admin_bar->add_menu( array(
		'parent' => 'user-actions',
		'id'     => 'logout',
		'title'  => __( 'Log Out' ),
		'href'   => wp_logout_url(),
	) );
}

更新日志

Version 描述
3.1.0 Introduced.

相关函数

Uses

  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/l10n.php:
    __()
  • wp-includes/pluggable.php:
    get_avatar()
  • wp-includes/pluggable.php:
    wp_get_current_user()
  • wp-includes/general-template.php:
    wp_logout_url()
  • wp-includes/load.php:
    is_multisite()
  • wp-includes/link-template.php:
    get_edit_profile_url()
  • wp-includes/link-template.php:
    get_dashboard_url()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::add_group()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::add_menu()
  • wp-includes/user.php:
    get_current_user_id()
  • Show 6 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!