WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/29/2010 05:48:53 PM (9 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r16030 r16083  
    22722272
    22732273/**
     2274 * Get the URL to the user's dashboard.
     2275 *
     2276 * If a user does not belong to any sites, the global user dashboard is used.  If the user belongs to the current site,
     2277 * the dashboard for the current site is returned.  If the user cannot edit the current site, the dashboard to the user's
     2278 * primary blog is returned.
     2279 *
     2280 * @since 3.1.0
     2281 *
     2282 * @param int $user_id User ID
     2283 * @param string $path Optional path relative to the dashboard.  Use only paths known to both blog and user admins.
     2284 * @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.
     2285 * @return string Dashboard url link with optional path appended
     2286 */
     2287function get_dashboard_url( $user_id, $path = '', $scheme = 'admin' ) {
     2288    $user_id = (int) $user_id;
     2289
     2290    $blogs = get_blogs_of_user( $user_id );
     2291    if ( empty($blogs) ) {
     2292        $url = user_admin_url( $path, $scheme );
     2293    } elseif ( ! is_multisite() ) {
     2294        $url = admin_url( $path, $scheme );
     2295    } else {
     2296        $current_blog = get_current_blog_id();
     2297        if ( $current_blog  && in_array($current_blog, array_keys($blogs)) ) {
     2298            $url = admin_url( $path, $scheme );
     2299        } else {
     2300            $active = get_active_blog_for_user( $user_id );
     2301            if ( $active )
     2302                $url = get_admin_url( $active->blog_id, $path, $scheme );
     2303            else
     2304                $url = user_admin_url( $path, $scheme );
     2305        }
     2306    }
     2307
     2308    return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme);
     2309}
     2310
     2311/**
     2312 * Get the URL to the user's profile editor.
     2313 *
     2314 * @since 3.1.0
     2315 *
     2316 * @param int $user User ID
     2317 * @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.
     2318 * @return string Dashboard url link with optional path appended
     2319 */
     2320function get_edit_profile_url( $user, $scheme = 'admin' ) {
     2321    $user = (int) $user;
     2322
     2323    $url = get_dashboard_url( $user, 'profile.php', $scheme );
     2324
     2325    return apply_filters( 'edit_profile_url', $url, $user, $scheme);
     2326}
     2327
     2328/**
    22742329 * Output rel=canonical for singular queries
    22752330 *
Note: See TracChangeset for help on using the changeset viewer.