+ * Retrieve the url to the admin area for the current user.
+ *
+ * @package WordPress
+ * @since 3.0.0
+ *
+ * @param string $path Optional path relative to the admin url.
+ * @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 Admin url link with optional path appended.
+*/
+function user_admin_url( $path = '', $scheme = 'admin' ) {
+ $url = network_site_url('wp-admin/user/', $scheme);
+
+ if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
+ $url .= ltrim($path, '/');
+
+ return apply_filters('user_admin_url', $url, $path);
+}
+
+/**
+ * Retrieve the url to the admin area for either the current blog or the network depending on context.
+ *
+ * @package WordPress
+ * @since 3.1.0
+ *
+ * @param string $path Optional path relative to the admin url.
+ * @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 Admin url link with optional path appended.
+*/
+function self_admin_url($path = '', $scheme = 'admin') {
+ if ( is_network_admin() )
+ return network_admin_url($path, $scheme);
+ elseif ( is_user_admin() )
+ return user_admin_url($path, $scheme);
+ else
+ return admin_url($path, $scheme);
+}
+
+/**
+ * Set the scheme for a URL
+ *
+ * @since 3.4.0
+ *
+ * @param string $url Absolute url that includes a scheme
+ * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
+ * @return string $url URL with chosen scheme.
+ */
+function set_url_scheme( $url, $scheme = null ) {
+ $orig_scheme = $scheme;
+ if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
+ if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
+ $scheme = 'https';
+ elseif ( ( 'login' == $scheme ) && force_ssl_admin() )
+ $scheme = 'https';
+ elseif ( ( 'admin' == $scheme ) && force_ssl_admin() )
+ $scheme = 'https';
+ else
+ $scheme = ( is_ssl() ? 'https' : 'http' );
+ }
+
+ if ( 'relative' == $scheme )
+ $url = preg_replace( '#^.+://[^/]*#', '', $url );
+ else
+ $url = preg_replace( '#^.+://#', $scheme . '://', $url );
+
+ return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
+}
+
+/**
+ * Get the URL to the user's dashboard.
+ *
+ * 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 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 ( ! is_super_admin() && 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 && ( is_super_admin( $user_id ) || 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;
+
+ if ( is_user_admin() )
+ $url = user_admin_url( 'profile.php', $scheme );
+ elseif ( is_network_admin() )
+ $url = network_admin_url( 'profile.php', $scheme );
+ else
+ $url = get_dashboard_url( $user, 'profile.php', $scheme );
+
+ return apply_filters( 'edit_profile_url', $url, $user, $scheme);
+}
+
+/**
+ * Output rel=canonical for singular queries.