Last active
June 8, 2018 19:33
-
-
Save bueltge/7abfbfc65f1f19a782cc to your computer and use it in GitHub Desktop.
MultilingualPress Alternative Title to Admin Bar Site links
This file contains hidden or 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: MultilingualPress Alternative Title to Admin Bar Site links | |
* Plugin URI: https://github.com/inpsyde/multilingual-press | |
* Description: | |
* Author: Inpsyde GmbH | |
* Author URI: http://inpsyde.com | |
* Version: 20.05.2015 | |
* Text Domain: multilingualpress | |
* Domain Path: /languages | |
* License: GPLv2+ | |
* Network: true | |
*/ | |
add_action( 'mlp_and_wp_loaded', 'mlp_site_link_admin_bar' ); | |
function mlp_site_link_admin_bar() { | |
add_action( 'admin_bar_menu', 'mlp_change_admin_bar_site_items', 11 ); | |
add_action( 'admin_bar_menu', 'mlp_change_admin_bar_site_name', 999 ); | |
} | |
/** | |
* Get alternative title, if exists | |
* | |
* @param $site_id | |
* | |
* @return bool | |
*/ | |
function mlp_get_alternative_title( $site_id ) { | |
// Get settings | |
$settings = get_site_option( 'inpsyde_multilingual' ); | |
// Get alternate site title | |
if ( isset( $settings[ $site_id ][ 'text' ] ) ) { | |
$site_title = $settings[ $site_id ][ 'text' ]; | |
} | |
if ( ! isset( $site_title ) ) { | |
return FALSE; | |
} | |
return $site_title; | |
} | |
/** | |
* Change strings inside the admin bar for User Sites | |
* | |
* @param $wp_admin_bar | |
* | |
* @return mixed | |
*/ | |
function mlp_change_admin_bar_site_items( $wp_admin_bar ) { | |
foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { | |
$alternative_title = mlp_get_alternative_title( $blog->userblog_id ); | |
if ( $alternative_title ) { | |
$wp_admin_bar->user->blogs[ $blog->userblog_id ]->blogname = $alternative_title; | |
} | |
} | |
return $wp_admin_bar; | |
} | |
/** | |
* Change strings inside the admin bar for site name of current site | |
* | |
* @param $wp_admin_bar | |
* | |
* @return mixed | |
*/ | |
function mlp_change_admin_bar_site_name( $wp_admin_bar ) { | |
$site_name = $wp_admin_bar->get_node( 'site-name' ); | |
$alternative_title = mlp_get_alternative_title( get_current_blog_id() ); | |
// Lease default in Network Admin Area | |
if ( is_network_admin() ) { | |
return $wp_admin_bar; | |
} | |
// Change title for each blog | |
if ( $alternative_title ) { | |
$wp_admin_bar->add_node( | |
array( | |
'id' => 'site-name', | |
'title' => $alternative_title, | |
) | |
); | |
} | |
return $wp_admin_bar; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment