-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.php
More file actions
218 lines (189 loc) · 7.6 KB
/
core.php
File metadata and controls
218 lines (189 loc) · 7.6 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
class AC_Core {
static $options;
static function init( $options ) {
self::$options = $options;
add_action( 'wp_dashboard_setup', array( __CLASS__, 'ac_dashboard_setup' ), 99);
add_action( 'admin_head', array( __CLASS__, 'ac_admin_head_setup' ) );
add_action( 'admin_init', array( __CLASS__, 'ac_remove_update_notices' ) );
add_action( 'admin_menu', array( __CLASS__, 'ac_remove_plugin_update_count' ) );
add_filter( 'admin_user_info_links', array( __CLASS__, 'ac_redirect_on_logout' ) );
add_action( 'login_head', array( __CLASS__, 'ac_login_head_setup' ) );
add_filter( 'login_headerurl', array( __CLASS__, 'ac_login_url' ) );
add_filter( 'login_headertitle', array( __CLASS__, 'ac_login_title' ) );
add_filter( 'admin_footer_text', array( __CLASS__, 'ac_footer_left' ) );
add_filter( 'update_footer', array( __CLASS__, 'ac_footer_right' ), 11 );
}
function ac_remove_update_notices() {
// global $current_user;
// get_currentuserinfo();
// if ($current_user->user_login != 'admin')
if ( in_array( 'hide_update_notices', (array) self::$options->general_settings ) )
remove_action('admin_notices', 'update_nag', 3);
}
function ac_remove_plugin_update_count() {
if ( in_array( 'hide_plugin_count', (array) self::$options->general_settings ) )
{
global $menu, $submenu;
$menu[65][0] = 'Plugins';
$submenu['index.php'][10][0] = 'Updates';
}
}
function ac_redirect_on_logout($links) {
if ( in_array( 'redirect_on_logout', (array) self::$options->general_settings ) ) {
$links[15] = '| <a href="' . wp_logout_url( home_url() ) . '" title="Log Out">Log Out</a>';
}
return $links;
}
function ac_admin_head_setup() {
// Make logo mark into a link
?>
<script type="text/javascript">
jQuery(document).ready(function() {
$logo_mark = jQuery('#header-logo');
$site_url = jQuery('<a href="<?php echo site_url(); ?>"></a>');
$site_url.append($logo_mark);
jQuery('#site-heading').before($site_url);
});
</script>
<?php
// Favicon
if ( !empty( self::$options->favicon ) )
echo '<link rel="shortcut icon" href="' . site_url() . '/wp-content/' . self::$options->favicon . '" />';
$styles = array();
// Fix wp 3.2 user info dropdown width bug
$styles[] = '
#user_info > div {
min-width: 95px !important;
}
';
// Backend logo name
$is_logo_text_hidden = false;
if ( in_array( 'hide_logo_name', (array) self::$options->style_settings ) ) {
$styles[] = '#site-heading { display: none !important }';
$is_logo_text_hidden = true;
}
// Backend logo
$is_logo_hidden = false;
if ( in_array( 'hide_logo', (array) self::$options->style_settings ) ) {
$styles[] = '#header-logo { display: none !important }';
$is_logo_hidden = true;
}
// Wordpress's default top, left margins
$margins = array( 7, 7 );
// Wordpress's default logo width and height
$logo_size = array( 16, 16 );
$font_size = $is_logo_text_hidden ? 16 : self::$options->admin_logo_font_size;
// if logo mark and name aren't both hidden
if ( ( count( (array)self::$options->style_settings ) < 2 ) ) {
// If admin logo needs to be set
if ( !empty( self::$options->admin_logo ) && file_exists( ABSPATH . 'wp-content/' . self::$options->admin_logo ) && !$is_logo_hidden ) {
// Get logo information
$logo_path = site_url( 'wp-content/' . self::$options->admin_logo );
$logo_size = getimagesize( $logo_path );
$styles[] ='
#header-logo {
background:url(' . $logo_path . ') left center no-repeat !important;
height: ' . $logo_size[1] . 'px !important;
width: ' . $logo_size[0] . 'px !important;
margin-top: ' . max( ( $font_size / 2 - $logo_size[1] / 2 + $margins[1] ), $margins[1] ) . 'px;
}';
$adjusted_head_height = max( $logo_size[1] + $margins[1] * 2, $font_size + $margins[1] * 2, 32 );
} else if ( !$is_logo_text_hidden ){
$styles[] ='
#header-logo {
margin-top: ' . max( ( $font_size / 2 - $logo_size[1] / 2 + $margins[1] ), $margins[1] ) . 'px;
}';
// Calculate the header height
$adjusted_head_height = max( 16 + $margins[1] * 2, $font_size + $margins[1] * 2, 32 );
}
if ( !empty( $adjusted_head_height ) ) {
$styles[] ='
#wphead {
height: ' . $adjusted_head_height . 'px;
}';
}
$styles[] ='
#wphead h1 {
margin-top:' . max( ( $logo_size[1] / 2 + $margins[1] - $font_size / 2 ), $margins[0] ) . 'px;
margin-left:' . ( $is_logo_hidden ? '0' : $margins[0] ) . 'px;
padding: 0;
font-size: '. $font_size . 'px;
line-height: '. $font_size . 'px;
}';
}
// Echo style modifications, if any
if ( !empty( $styles ) ) {
echo '<style type="text/css">';
foreach ( $styles as $rule ){
echo $rule;
}
echo '</style>';
}
}
function ac_login_head_setup() {
if ( !empty( self::$options->login_logo ) ) {
$logo_path = site_url() . '/wp-content/' . self::$options->login_logo;
$logo_size = getimagesize( $logo_path );
$wp_default_width = 320;
echo '<style type="text/css">
h1 a
{
background:url(' . $logo_path . ') center top no-repeat !important;
height: '. $logo_size[1] . 'px;
width: auto !important;
}
#login {
width: ' . max( $logo_size[0], $wp_default_width ). 'px;
}
form {
margin-left: 0;
}
</style>';
}
}
function ac_login_url() {
echo home_url();
}
function ac_login_title() {
echo get_option( 'blogname' );
}
function ac_footer_left( $footer_text ) {
if ( !empty( self::$options->admin_footer_left ) ) {
return htmlspecialchars_decode ( self::$options->admin_footer_left );
} else {
return $footer_text;
}
}
function ac_footer_right( $upgrade ) {
if ( !empty( self::$options->admin_footer_right ) ) {
return htmlspecialchars_decode ( self::$options->admin_footer_right );
} else {
return $upgrade;
}
}
function ac_dashboard_setup() {
global $wp_meta_boxes;
self::$options->widgets = self::_get_unset_dashboard_widgets(self::$options->disabled_widgets);
}
private function _get_unset_dashboard_widgets($disabled_widgets = array()) {
global $wp_meta_boxes;
if ( isset($wp_meta_boxes['dashboard']) ) {
foreach ( $wp_meta_boxes['dashboard'] as $context => $data ) {
foreach ( $data as $priority=>$data ) {
foreach( $data as $widget=>$data ) {
$widgets[$widget] = array('id' => $widget,
'title' => strip_tags( preg_replace('/( |)<span.*span>/im', '', $data['title']) ),
'context' => $context,
'priority' => $priority
);
// unset the required widgets
if ( in_array( $widget, (array) $disabled_widgets ) )
unset($wp_meta_boxes['dashboard'][$context][$priority][$widget]);
}
}
}
}
return $widgets;
}
}