返回介绍

get_dashboard_url()

发布于 2017-09-10 23:13:26 字数 4090 浏览 1057 评论 0 收藏 0

get_dashboard_url( int $user_id,  string $path = '',  string $scheme = 'admin' )

Retrieves the URL to the user’s dashboard.


description

If a user does not belong to any site, the global user dashboard is used. If the user belongs to the current site, the dashboard for the current site is returned. If the user cannot edit the current site, the dashboard to the user’s primary site is returned.


参数

$user_id

(int) (Optional) User ID. Defaults to current user.

$path

(string) (Optional) path relative to the dashboard. Use only paths known to both site and user admins.

Default value: ''

$scheme

(string) (Optional) The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.

Default value: 'admin'


返回值

(string) Dashboard URL link with optional path appended.


源代码

File: wp-includes/link-template.php

function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
	$user_id = $user_id ? (int) $user_id : get_current_user_id();

	$blogs = get_blogs_of_user( $user_id );
	if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty($blogs) ) {
		$url = user_admin_url( $path, $scheme );
	} elseif ( ! is_multisite() ) {
		$url = admin_url( $path, $scheme );
	} else {
		$current_blog = get_current_blog_id();
		if ( $current_blog  && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
			$url = admin_url( $path, $scheme );
		} else {
			$active = get_active_blog_for_user( $user_id );
			if ( $active )
				$url = get_admin_url( $active->blog_id, $path, $scheme );
			else
				$url = user_admin_url( $path, $scheme );
		}
	}

	/**
	 * Filters the dashboard URL for a user.
	 *
	 * @since 3.1.0
	 *
	 * @param string $url     The complete URL including scheme and path.
	 * @param int    $user_id The user ID.
	 * @param string $path    Path relative to the URL. Blank string if no path is specified.
	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
	 *                        'login_post', 'admin', 'relative' or null.
	 */
	return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme);
}

更新日志

Versiondescription
3.1.0Introduced.

相关函数

Uses

  • wp-includes/capabilities.php: user_can()
  • wp-includes/load.php: is_multisite()
  • wp-includes/load.php: get_current_blog_id()
  • wp-includes/link-template.php: user_dashboard_url
  • wp-includes/link-template.php: user_admin_url()
  • wp-includes/link-template.php: admin_url()
  • wp-includes/link-template.php: get_admin_url()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/user.php: get_blogs_of_user()
  • wp-includes/user.php: get_current_user_id()
  • wp-includes/ms-functions.php: get_active_blog_for_user()
  • Show 6 more uses Hide more uses

Used By

  • wp-includes/deprecated.php: wp_admin_bar_dashboard_view_site_menu()
  • wp-includes/link-template.php: get_edit_profile_url()
  • wp-includes/admin-bar.php: wp_admin_bar_wp_menu()
  • wp-includes/admin-bar.php: wp_admin_bar_my_account_item()
  • wp-includes/admin-bar.php: wp_admin_bar_my_account_menu()

User Contributed Notes

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

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

发布评论

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