forked from Automattic/babble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-admin-bar.php
48 lines (40 loc) · 1.12 KB
/
class-admin-bar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Class to handle adding our links to the admin bar.
*
* @package Babble
* @since 0.2
*/
class Babble_Admin_bar extends Babble_Plugin {
function __construct() {
$this->setup( 'babble-switcher-menu', 'plugin' );
$this->add_action( 'admin_bar_menu', null, 100 );
}
/**
* Hooks the WP admin_bar_menu action
*
* @param object $wp_admin_bar The WP Admin Bar, passed by reference
* @return void
**/
public function admin_bar_menu( $wp_admin_bar ) {
$links = bbl_get_switcher_links( 'bbl-admin-bar' );
$current_lang = bbl_get_current_lang();
// Remove the current language
unset( $links[ $current_lang->code ] );
$parent_id = "bbl-admin-bar-{$current_lang->url_prefix}";
$wp_admin_bar->add_menu( array(
'children' => array(),
'href' => '#',
'id' => $parent_id,
'meta' => array( 'class' => "bbl_lang_{$current_lang->code} bbl_lang" ),
'title' => $current_lang->display_name,
'parent' => false,
) );
foreach ( $links as & $link ) {
$link[ 'parent' ] = $parent_id;
$wp_admin_bar->add_menu( $link );
}
}
}
global $bbl_admin_bar;
$bbl_admin_bar = new Babble_Admin_bar();