get_dashboard_url

函数
get_dashboard_url ( $user_id = 0, $path = '', $scheme = 'admin' )
参数
  • (int) $user_id Optional. User ID. Defaults to current user.
    Required:
  • (string) $path Optional path relative to the dashboard. Use only paths known to both site and user admins. Default empty.
    Required:
    Default: (empty)
  • (string) $scheme 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.
    Required:
    Default: 'admin'
返回值
  • (string) Dashboard URL link with optional path appended.
定义位置
相关方法
get_dashboard_blogget_avatar_urlwp_dashboard_quotawp_dashboardwp_dashboard_setup
引入
3.1.0
弃用
-

get_dashboard_url:该函数返回当前站点的管理仪表盘的URL。

检索用户仪表盘的URL。

如果一个用户不属于任何站点,则使用全局用户仪表盘。如果用户属于当前站点,将返回当前站点的仪表盘。如果用户不能编辑当前站点,将返回用户主要站点的仪表盘。

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 ), true ) ) ) {
			$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 );
}

常见问题

FAQs
查看更多 >