Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to add an area on the admin bar that will display user Profile Image, User Name, User Email, User role, and links to Edit Profile and signout. The way in which I would like it to display is

Steve Jackson - stevejack@yahoo.com

Author

Edit Profile <<< "Link"

Signout <<< "Link"

With the user image to the left of the user info

Some far I have gotten the secondary div area in the admin bar to show without a dropdown menu and the hack the admin-bar.php file to display User Image, Name and email with this function

function wp_admin_bar_my_account_item( $wp_admin_bar ) {
$user_id      = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url  = get_edit_profile_url( $user_id );

if ( ! $user_id )
    return;

$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_email )
    $user_info .= "<span class='username'>&nbsp;-&nbsp;{$current_user->user_email}</span>";


$wp_admin_bar->add_menu( array(
    'id'        => 'my-account',
    'parent'    => 'top-secondary',
    'title'     => $user_info,
    'meta'      => array(
        'class'     => $class,
        'title'     => __('My Account'),
    ),
) );
}
share|improve this question
    
There are a ton of plugins out there that add things to the admin bar without directly hacking the file that you could have referenced, in addition the first result when you google "Add things to wp admin bar" is an article telling you what to hook to. –  Andrew Bartel May 2 '13 at 0:04
2  
Hi and welcome, herb. Take a look at this, maybe you can grab some inspiration. Researching for +wp_admin_bar +add_menu is:answer may help too. –  brasofilo May 2 '13 at 0:21
    
@brasofilo Thanks man for the links and advice –  Jusherb May 2 '13 at 4:43
    
@AndrewBartel I actually would prefer hacking trying to learn so that I can build my own plugins and backends. Thanks for the advice though. –  Jusherb May 2 '13 at 4:44
    
After reading brasfolio's comment, may initial reaction was probably too harsh. Welcome to the site, but please understand, hacking any core file will always result in more headaches than it is worth. Best practices exist for a reason. If you want to write plugins, you're going to have to find ways to hook into WordPress rather than overwriting code anyway. –  Andrew Bartel May 2 '13 at 18:28
add comment

1 Answer 1

up vote 0 down vote accepted

I think you need to use "global $current_user;" in your function to get the details of $current_user and global $wp_admin_bar; for admin bar.

This is how I managed to get the role of the current user and change the URL from admin depending on role (It doesn't solve your issue, but maybe you find it helpful)

function mytheme_admin_bar_render() {
global $wp_admin_bar;
global $current_user;


    if (!is_admin()) {
        $adminUrl = admin_url();
        $wp_admin_bar->add_menu( array(
            'parent' => false,
            'id' => 'am-profile',
            'title' => __('Admin's Title'),
            'href' => $adminUrl
        ));
    }else{
        $profilehref = site_url();
        $wp_admin_bar->add_menu( array(
            'parent' => false,
            'id' => 'some_id',
            'title' => __($sitereturnto),
            'href' => $profilehref 
        ));
    }
}

add_action( 'admin_bar_menu', 'mytheme_admin_bar_render', 20 );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.