get_dashboard_url() and get_edit_profile_url(). Determine the appropriate dahboard for a user based on the user's blogs and the current blog. see #14696 #14772
git-svn-id: https://develop.svn.wordpress.org/trunk@16083 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
59a291483f
commit
40558c2dbc
@ -82,13 +82,15 @@ function wp_admin_bar_me_separator() {
|
||||
function wp_admin_bar_my_account_menu() {
|
||||
global $wp_admin_bar, $user_identity;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
/* Add the 'My Account' menu */
|
||||
$wp_admin_bar->add_menu( array( 'id' => 'my-account', 'title' => $user_identity, 'href' => admin_url('profile.php'), ) );
|
||||
|
||||
/* Add the "My Account" sub menus */
|
||||
$wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Edit My Profile' ), 'href' => admin_url('profile.php'), ) );
|
||||
$wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Edit My Profile' ), 'href' => get_edit_profile_url( $user_id ) ) );
|
||||
if ( is_multisite() )
|
||||
$wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Global Dashboard' ), 'href' => admin_url(), ) );
|
||||
$wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Dashboard' ), 'href' => get_dashboard_url( $user_id ), ) );
|
||||
else
|
||||
$wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Dashboard' ), 'href' => admin_url(), ) );
|
||||
$wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Log Out' ), 'href' => wp_logout_url(), ) );
|
||||
|
@ -2270,6 +2270,61 @@ function self_admin_url($path = '', $scheme = 'admin') {
|
||||
return admin_url($path, $scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to the user's dashboard.
|
||||
*
|
||||
* If a user does not belong to any sites, 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 blog is returned.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param int $user_id User ID
|
||||
* @param string $path Optional path relative to the dashboard. Use only paths known to both blog and user admins.
|
||||
* @param 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.
|
||||
* @return string Dashboard url link with optional path appended
|
||||
*/
|
||||
function get_dashboard_url( $user_id, $path = '', $scheme = 'admin' ) {
|
||||
$user_id = (int) $user_id;
|
||||
|
||||
$blogs = get_blogs_of_user( $user_id );
|
||||
if ( 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 && 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 );
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to the user's profile editor.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param int $user User ID
|
||||
* @param 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.
|
||||
* @return string Dashboard url link with optional path appended
|
||||
*/
|
||||
function get_edit_profile_url( $user, $scheme = 'admin' ) {
|
||||
$user = (int) $user;
|
||||
|
||||
$url = get_dashboard_url( $user, 'profile.php', $scheme );
|
||||
|
||||
return apply_filters( 'edit_profile_url', $url, $user, $scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output rel=canonical for singular queries
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user