返回介绍

wp_admin_bar_site_menu()

发布于 2017-09-11 11:21:53 字数 3894 浏览 1029 评论 0 收藏 0

wp_admin_bar_site_menu( WP_Admin_Bar $wp_admin_bar )

Add the “Site Name” menu.


description


参数

$wp_admin_bar

(WP_Admin_Bar) (Required)


源代码

File: wp-includes/admin-bar.php

function wp_admin_bar_site_menu( $wp_admin_bar ) {
	// Don't show for logged out users.
	if ( ! is_user_logged_in() )
		return;

	// Show only when the user is a member of this site, or they're a super admin.
	if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) {
		return;
	}

	$blogname = get_bloginfo('name');

	if ( ! $blogname ) {
		$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
	}

	if ( is_network_admin() ) {
		/* translators: %s: site name */
		$blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) );
	} elseif ( is_user_admin() ) {
		/* translators: %s: site name */
		$blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) );
	}

	$title = wp_html_excerpt( $blogname, 40, '…' );

	$wp_admin_bar->add_menu( array(
		'id'    => 'site-name',
		'title' => $title,
		'href'  => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
	) );

	// Create submenu items.

	if ( is_admin() ) {
		// Add an option to visit the site.
		$wp_admin_bar->add_menu( array(
			'parent' => 'site-name',
			'id'     => 'view-site',
			'title'  => __( 'Visit Site' ),
			'href'   => home_url( '/' ),
		) );

		if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
			$wp_admin_bar->add_menu( array(
				'parent' => 'site-name',
				'id'     => 'edit-site',
				'title'  => __( 'Edit Site' ),
				'href'   => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
			) );
		}

	} else if ( current_user_can( 'read' ) ) {
		// We're on the front end, link to the Dashboard.
		$wp_admin_bar->add_menu( array(
			'parent' => 'site-name',
			'id'     => 'dashboard',
			'title'  => __( 'Dashboard' ),
			'href'   => admin_url(),
		) );

		// Add the appearance submenu items.
		wp_admin_bar_appearance_menu( $wp_admin_bar );
	}
}

更新日志

Versiondescription
3.3.0Introduced.

相关函数

Uses

  • wp-includes/ms-blogs.php: get_network()
  • wp-includes/capabilities.php: current_user_can()
  • wp-includes/l10n.php: __()
  • wp-includes/formatting.php: wp_html_excerpt()
  • wp-includes/formatting.php: esc_html()
  • wp-includes/pluggable.php: is_user_logged_in()
  • wp-includes/general-template.php: get_bloginfo()
  • wp-includes/load.php: is_network_admin()
  • wp-includes/load.php: is_user_admin()
  • wp-includes/load.php: is_admin()
  • wp-includes/load.php: is_blog_admin()
  • wp-includes/load.php: is_multisite()
  • wp-includes/load.php: get_current_blog_id()
  • wp-includes/link-template.php: admin_url()
  • wp-includes/link-template.php: network_admin_url()
  • wp-includes/link-template.php: get_home_url()
  • wp-includes/link-template.php: home_url()
  • wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::add_menu()
  • wp-includes/admin-bar.php: wp_admin_bar_appearance_menu()
  • wp-includes/user.php: is_user_member_of_blog()
  • Show 15 more uses Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文