=' ) ) { // Get native language names if( file_exists( ABSPATH . 'wp-admin/includes/translation-install.php' ) ) require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); $translations = ( function_exists( 'wp_get_available_translations' ) ) ? wp_get_available_translations() : array(); } else { $translations = array(); } // Loop user's blogs trough foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { $node_id = 'blog-' . $blog->userblog_id; $node = $wp_admin_bar->get_node( $node_id ); if ( $node ) { // We'll put it back... $wp_admin_bar->remove_node( $node_id ); // Get language $lang = ( is_multisite() ) ? get_blog_option( $blog->userblog_id, 'WPLANG', 'en_US' ) : get_bloginfo( 'language' ); // Oh, just sometimes language returns empty on WP 4.0, try different key if( empty( $lang ) && is_multisite() ) $lang = get_blog_option( $blog->userblog_id, 'language', 'en_US' ); // Still no language? Default to US. if( empty( $lang ) ) $lang = 'en_US'; // Blog name - and is this blog currently active? $blogname = ( $blog_id == $blog->userblog_id ) ? '' . $blog->blogname . '' : $blog->blogname; // Update node and put it back $node->title = '
' . $blogname; // If we have name for this language, show it as title. Fall back to locale. $node->meta['title'] = isset( $translations[ $lang ] ) ? esc_attr( $translations[ $lang ]['english_name'] . ' (' . $translations[ $lang ]['native_name'] . ')' ) : esc_attr( $lang ); $wp_admin_bar->add_node( $node ); } } } /* * Add donation link on the plugin listing */ public function flagatar_plugin_links( $links, $file ) { if ( $file == plugin_basename( dirname(__FILE__).'/admin-bar-languages.php' ) ) { $links[] = '' . __( 'Donate' ) . ''; } return $links; } } $AdminBarLanguages = new AdminBarLanguages();