This is a little tricky, and I don't know if I got the best solution for this. However, it works.
The trick is, I use the same hook as you do, wp_before_admin_bar_render
. In there I get all the elements, and check them if they have the parent my-sites-list
.
If they do, I switch to the blog, get the language of the current blog, create the title and call restore_current_blog().
After that, I create a new admin bar item, containing all the original information but the new title, remove the old one and insert the new one right afterwards.
Issues/concernces
- I could not find out by now if there is a way to get a blogs language without switching to it.
- Maybe there is a filter for the generation of the admin bar menu items. It would be much better to filter those titles there than manipulating them afterwards.
The function
function f711_tweaked_admin_bar() {
global $wp_admin_bar;
$elements = $wp_admin_bar->get_nodes();
foreach( $elements as $element ) {
if ( $element->parent == 'my-sites-list' ) {
// reduce the adminbar Id to the blog ID
$idinteger = str_replace( 'blog-', '', $element->id );
// Switch to the Blog, get the language option. If empty, it's English
switch_to_blog( $idinteger );
if ( get_option( 'WPLANG' ) != "" ) {
$language = get_option( 'WPLANG' );
} else {
$language = 'en_EN';
}
//set the new title for the Admin Menu
$newtitle = $element->title . ' - ' . $language;
restore_current_blog();
// define new menu element
$args = array(
'title' => $newtitle,
'id' => $element->id,
'parent' => $element->parent,
'href' => $element->href,
);
// remove the old one
$wp_admin_bar->remove_node( $element->id );
// add the new one right afterwards.
$wp_admin_bar->add_node( $args );
}
}
}
add_action( 'wp_before_admin_bar_render', 'f711_tweaked_admin_bar' );