Last active
January 26, 2017 14:29
-
-
Save Drivingralle/2934fe51476ea03c01fd3daff3f3032a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Cross Media Cloud | Add language slug to blog name in admin bar | |
* Description: Show the blog language within the drop down of sites within the admin bar | |
* Version: 1.0 | |
* Author: Cross Media Cloud | |
* Author URI: https://www.cross-media-cloud.de | |
* License: GNU General Public License v2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
if( ! defined( 'ABSPATH' ) ) | |
exit; | |
add_action('wp_before_admin_bar_render', 'add_language_to_blog_name'); | |
function add_language_to_blog_name( $wp_admin_bar ) { | |
global $wp_admin_bar; | |
$wp_admin_bar->add_menu( array( | |
'id' => 'site-name', | |
'title' => get_bloginfo( 'name' ) . ' | ' . get_bloginfo( 'language' ), | |
) ); | |
} | |
add_action( 'wp_before_admin_bar_render', 'f711_tweaked_admin_bar' ); | |
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 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment