BuddyDev

Search

[Resolved] Need a little help with this code

  • Participant
    Level: Enlightened
    Posts: 69
    Christopher Niedzwiecki on #6922

    I used this to try and add a link in the adminbar drop down menu. It worked, but the link is blank. I want it to say “Username”, but I don’t know where to put it lol.

    /**
    * add change username to adminbar
    */
    function buddydev_update_personal_activity_in_admin_bar3() {
    global $wp_admin_bar;

    if ( ! is_user_logged_in() ) {
    return ;
    }

    // Update personal activity Url for the logged in user
    $wp_admin_bar->add_menu( array(
    ‘parent’ => ‘my-account-settings’,
    ‘id’ => ‘change-username’,
    ‘href’ => bp_loggedin_user_domain() . ‘settings/change-username/’,
    ) );
    }
    add_action( ‘bp_activity_setup_admin_bar’, ‘buddydev_update_personal_activity_in_admin_bar3’, 100 );

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #6925

    Hi Chris,
    you will need to pass title like this

    
    
    /**
     * add change username to adminbar
     */
    function buddydev_update_personal_activity_in_admin_bar3() {
    	global $wp_admin_bar;
    
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
    // Update personal activity Url for the logged in user
    	$wp_admin_bar->add_menu( array(
    		'parent' => 'my-account-settings',
    		'id'     => 'change-username',
    		'title'  => 'Username',
    		'href'   => bp_loggedin_user_domain() . 'settings/change-username/',
    	) );
    }
    
    add_action( 'bp_activity_setup_admin_bar', 'buddydev_update_personal_activity_in_admin_bar3', 100 );
    
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 69
    Christopher Niedzwiecki on #6927

    ahhhh, thanks a lot! Is there a way to change the order on the menu? By default it’s appearing above all other items.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #6932

    Hi Chris,
    The WordPress admibar does not allow specifying the priority. The solution is to delay the adding of menu item.

    You can change the action hook to this

    
    
    add_action( 'wp_before_admin_bar_render', 'buddydev_update_personal_activity_in_admin_bar3', 100 );
    
    

    and it will add at the bottom of the settings menu.

  • Participant
    Level: Enlightened
    Posts: 69
    Christopher Niedzwiecki on #6934

    Aw, well thanks a lot for the help 🙂

You must be logged in to reply to this topic.

This topic is: resolved