forked from ServerPress/local-admin-color-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-admin-bar-color.php
97 lines (78 loc) · 2.08 KB
/
local-admin-bar-color.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Plugin Name: Local Admin Color Bar
* Plugin URL: https://serverpress.com/plugins/local-admin-bar-color
* Description: Changes the Admin bar color
* Version: 1.0.1
* Author: Gregg Franklin
* Author URI: http://greggfranklin.com
*/
/*
*
*/
function ds_admin_bar_init() {
if ( is_admin_bar_showing() ) {
// Add admin notice
add_action( 'admin_bar_menu', 'ds_admin_bar_notice' );
// Style the admin bar
add_action( 'admin_head', 'ds_admin_bar_notice_css' );
add_action( 'wp_head', 'ds_admin_bar_notice_css' );
// Remove "howdy" message
add_filter( 'admin_bar_menu', 'ds_goodbye_howdy',25 );
}
}
add_action( 'init', 'ds_admin_bar_init' );
/*
* Add admin notice
*/
function ds_admin_bar_notice() {
if ( defined( 'ENV_TEXT' ) && ENV_TEXT ) {
$env_text = ENV_TEXT;
} else {
$env_text = 'LOCAL DEVELOPMENT WEBSITE';
}
$admin_notice = array(
'parent' => 'top-secondary', /** puts it on the right side. */
'id' => 'environment-notice',
'title' => '<span>' . $env_text . '</span>',
);
global $wp_admin_bar;
$wp_admin_bar->add_menu( $admin_notice );
}
/*
* Style the admin bar
*/
function ds_admin_bar_notice_css() {
if ( defined( 'DS_COLOR' ) && DS_COLOR ) {
$env_color = strtolower( DS_COLOR );
} else {
$env_color = '#0073AA';
}
echo "<!-- WPLT Admin Bar Notice -->
<style type='text/css'>
#wp-admin-bar-environment-notice>div,
#wpadminbar { background-color: $env_color !important }
#wp-admin-bar-environment-notice { display: none }
@media only screen and (min-width:1030px) {
#wp-admin-bar-environment-notice { display: block }
#wp-admin-bar-environment-notice>div>span {
color: #EEE!important;
font-size: 130%!important;
}
}
#adminbarsearch:before,
.ab-icon:before,
.ab-item:before { color: #EEE !important }
</style>";
}
/*
* Remove "howdy" message
*/
function ds_goodbye_howdy( $wp_admin_bar ) {
$my_account = $wp_admin_bar->get_node( 'my-account' );
$newtitle = str_replace( 'Howdy,', '', $my_account->title );
$wp_admin_bar->add_node( array(
'id' => 'my-account',
'title' => $newtitle,
) );
}