get_dashboard_url( int $user_id = 0, string $path = '', string $scheme = 'admin' ): string
- Since
- 3.1.0
- Source
wp-includes/link-template.php:3976
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.
Compatibility
- WordPress
- since 3.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$user_idintoptional- User ID. Defaults to current user.Default:
0 $pathstringoptional- Optional path relative to the dashboard. Use only paths known to both site and user admins. Default empty.Default:
'' $schemestringoptional- 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:
'admin'
Return value
string- Dashboard URL link with optional path appended.
Performance profile
How much work a call to get_dashboard_url() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Moderate
- Scaling
- Constant
- Instructions
- 31–62
- Plugin surface
- 1 hook
- Called by
- 5
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 87.
Third-party callbacks on 'user_dashboard_url' run inside this call, and their cost is not bounded by anything here.
5 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below get_dashboard_url()
Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 30 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_dashboard_url() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_multisite() | 31 | get_blogs_of_user(), is_multisite(), is_multisite(), admin_url(), apply_filters() |
!is_multisite() | 32 | get_current_user_id(), get_blogs_of_user(), is_multisite(), is_multisite(), admin_url(), apply_filters() |
is_multisite() && !user_can() && empty($blogs) | 35 | get_blogs_of_user(), is_multisite(), user_can(), user_admin_url(), apply_filters() |
is_multisite() && !user_can() && empty($blogs) | 36 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), user_admin_url(), apply_filters() |
| always | 36–38 | get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), admin_url(), apply_filters() |
| always | 37–39 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), admin_url(), apply_filters() |
| always | 39 | get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
user_can() | 40 | get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), admin_url(), apply_filters() |
| always | 40 | get_current_user_id(), get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
user_can() | 41 | get_current_user_id(), get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), admin_url(), apply_filters() |
| always | 43 | get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
| always | 44 | get_current_user_id(), get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
18 further outcomes, up to 62 instructions
is_multisite() | 44–46 | get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
is_multisite() && user_can() | 45–47 | get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), admin_url(), apply_filters() |
is_multisite() | 45–47 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
!user_can() && $current_blog | 46 | get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), admin_url(), apply_filters() |
is_multisite() && user_can() | 46–48 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), admin_url(), apply_filters() |
!user_can() && $current_blog | 47 | get_current_user_id(), get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), admin_url(), apply_filters() |
is_multisite() | 48–50 | get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
is_multisite() | 49–51 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
!user_can() && !$current_blog | 50 | get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
is_multisite() && !user_can() && $current_blog | 51–53 | get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), admin_url(), apply_filters() |
!user_can() && !$current_blog | 51 | get_current_user_id(), get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
is_multisite() && !user_can() && $current_blog | 52–54 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), admin_url(), apply_filters() |
!user_can() && !$current_blog | 54 | get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
!user_can() && !$current_blog | 55 | get_current_user_id(), get_blogs_of_user(), is_multisite(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
is_multisite() && !user_can() && !$current_blog | 55–57 | get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
is_multisite() && !user_can() && !$current_blog | 56–58 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), user_admin_url(), apply_filters() |
is_multisite() && !user_can() && !$current_blog | 59–61 | get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
is_multisite() && !user_can() && !$current_blog | 60–62 | get_current_user_id(), get_blogs_of_user(), is_multisite(), user_can(), is_multisite(), get_current_blog_id(), user_can(), array_keys(), get_active_blog_for_user(), get_admin_url(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 86 | 31–61 | 9 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 87 | 31–62 | 9 | |
| 8.4 | 87 | 31–62 | 9 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 90 | 31–65 | 9 | |
| 8.2 | 90 | 31–65 | 9 | |
| 8.1 | 90 | 31–65 | 9 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 91 | 32–65 | 9 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while get_dashboard_url() runs, in this order:
- apply_filters( user_dashboard_url )filterline 4011 (+35 into the body)
Filters the dashboard URL for a user.
Uses · 10
- get_current_user_id()Gets the current user's ID.
- get_blogs_of_user()Gets the sites a user belongs to.
- is_multisite()Determines whether Multisite is enabled.
- user_can()Returns whether a particular user has the specified capability.
- user_admin_url()Retrieves the URL to the admin area for the current user.
- admin_url()Retrieves the URL to the admin area for the current site.
- get_current_blog_id()Retrieves the current site ID.
- get_active_blog_for_user()Gets one of a user's active blogs.
- get_admin_url()Retrieves the URL to the admin area for a given site.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 5
- get_edit_profile_url()Retrieves the URL to the user's profile editor.
- wp_admin_bar_dashboard_view_site_menu()Add the "Dashboard"/"Visit Site" menu.
- wp_admin_bar_my_account_item()Adds the "My Account" item.
- wp_admin_bar_my_account_menu()Adds the "My Account" submenu items.
- wp_admin_bar_wp_menu()Adds the WordPress logo menu.
Source code
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 );}Changelog
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.