wp_admin_bar_my_account_menu( WP_Admin_Bar $wp_admin_bar )
- Since
- 3.1.0
- Source
wp-includes/admin-bar.php:302
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
$wp_admin_barWP_Admin_Bar- The WP_Admin_Bar instance.
Performance profile
How much work a call to wp_admin_bar_my_account_menu() 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
- 9–71
- Plugin surface
- None
- Called by
- 0
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 78.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_admin_bar_my_account_menu() - optionoption read or write
get_option()one call below wp_admin_bar_my_account_menu()
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 · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_admin_bar_my_account_menu() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9 | get_current_user_id(), wp_get_current_user() |
!current_user_can() && !is_multisite() && $profile_url === false | 55–60 | get_current_user_id(), wp_get_current_user(), current_user_can(), is_multisite(), ->add_group(), get_avatar(), user-actions(), __(), wp_logout_url(), user-actions() |
current_user_can() && $profile_url === false | 56–61 | get_current_user_id(), wp_get_current_user(), current_user_can(), get_edit_profile_url(), ->add_group(), get_avatar(), user-actions(), __(), wp_logout_url(), user-actions() |
!current_user_can() && is_multisite() && $profile_url === false | 60–65 | get_current_user_id(), wp_get_current_user(), current_user_can(), is_multisite(), get_dashboard_url(), ->add_group(), get_avatar(), user-actions(), __(), wp_logout_url(), user-actions() |
!current_user_can() && !is_multisite() && $profile_url !== false | 61–66 | get_current_user_id(), wp_get_current_user(), current_user_can(), is_multisite(), ->add_group(), get_avatar(), __(), user-actions(), __(), wp_logout_url(), user-actions() |
current_user_can() && $profile_url !== false | 62–67 | get_current_user_id(), wp_get_current_user(), current_user_can(), get_edit_profile_url(), ->add_group(), get_avatar(), __(), user-actions(), __(), wp_logout_url(), user-actions() |
!current_user_can() && is_multisite() && $profile_url !== false | 66–71 | get_current_user_id(), wp_get_current_user(), current_user_can(), is_multisite(), get_dashboard_url(), ->add_group(), get_avatar(), __(), user-actions(), __(), wp_logout_url(), user-actions() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 78 instructions, 9–71 executed per call, 5 branches. The work does not change between versions.
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.
Uses · 9
- get_current_user_id()Gets the current user's ID.
- wp_get_current_user()Retrieves the current user object.
- current_user_can()Returns whether the current user has the specified capability.
- get_edit_profile_url()Retrieves the URL to the user's profile editor.
- is_multisite()Determines whether Multisite is enabled.
- get_dashboard_url()Retrieves the URL to the user's dashboard.
- get_avatar()Retrieves the avatar `` tag for a user, email address, MD5 hash, comment, or post.
- __()Retrieves the translation of $text.
- wp_logout_url()Retrieves the logout URL.
Source code
function wp_admin_bar_my_account_menu( $wp_admin_bar ) { $user_id = get_current_user_id(); $current_user = wp_get_current_user(); if ( ! $user_id ) { return; } if ( current_user_can( 'read' ) ) { $profile_url = get_edit_profile_url( $user_id ); } elseif ( is_multisite() ) { $profile_url = get_dashboard_url( $user_id, 'profile.php' ); } else { $profile_url = false; } $wp_admin_bar->add_group( array( 'parent' => 'my-account', 'id' => 'user-actions', ) ); $user_info = get_avatar( $user_id, 64 ); $user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; if ( $current_user->display_name !== $current_user->user_login ) { $user_info .= "<span class='username'>{$current_user->user_login}</span>"; } if ( false !== $profile_url ) { $user_info .= "<span class='display-name edit-profile'>" . __( 'Edit Profile' ) . '</span>'; } $wp_admin_bar->add_node( array( 'parent' => 'user-actions', 'id' => 'user-info', 'title' => $user_info, 'href' => $profile_url, ) ); $wp_admin_bar->add_node( array( 'parent' => 'user-actions', 'id' => 'logout', 'title' => __( 'Log Out' ), 'href' => wp_logout_url(), ) );}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 7.1.0 tag, from
src/wp-includes/admin-bar.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.