PluginProbe
Adminimize / 1.9.1
Adminimize v1.9.1
1.11.14 1.11.13 1.11.1 1.11.10 1.11.11 1.11.12 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.11.7 1.11.8 1.11.9 1.3 1.4.7 1.6 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 All 53 releases
← All changes | inc-setup/remove-admin-bar.php +85 -139 1.11.11 → 1.9.1 View file →
@@ -1,19 +1,16 @@
1 1 <?php
2 2 /**
3 - * Functions to remove the admin bar.
4 - *
5 3 * @package Adminimize
6 - * @subpackage Remove Admin Bar of > WP 3.3 Setup
4 + * @subpackage Remove Admin Bar of WP 3.3 Setup
7 5 * @author Frank Bültge
8 6 */
9 -
10 7 if ( ! function_exists( 'add_action' ) ) {
11 8 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
12 9 exit;
13 10 }
14 11
15 -// on init of WordPress.
12 +// on init of WordPress
16 13 add_action( 'init', '_mw_adminimize_remove_admin_bar', 0 );
17 14
18 15 /**
19 16 * Change the var of Admin Bar in WP 3.3
@@ -19,19 +16,14 @@
19 16 * Change the var of Admin Bar in WP 3.3
20 17 *
21 18 * @param array $admin_bar_keys
22 19 */
23 -function _mw_adminimize_customize_admin_bar( array $admin_bar_keys ) {
20 +function _mw_adminimize_customize_admin_bar( $admin_bar_keys = array() ) {
24 21
25 22 if ( ! is_admin_bar_showing() ) {
26 23 return;
27 24 }
28 25
29 - /**
30 - * Reference to the doc to know the method.
31 - *
32 - * @var \WP_Admin_Bar $wp_admin_bar
33 - */
34 26 global $wp_admin_bar;
35 27
36 28 foreach ( $admin_bar_keys as $key ) {
37 29 $wp_admin_bar->remove_menu( $key );
@@ -37,9 +29,9 @@
37 29 $wp_admin_bar->remove_menu( $key );
38 30 }
39 31 }
40 32
41 -/**
33 +/*
42 34 * Remove my account item in admin bar >3.3
43 35 */
44 36 function _mw_adminimize_remove_my_account() {
45 37
@@ -48,17 +40,18 @@
48 40
49 41 /**
50 42 * Add Logout link to admin abr in wp 3.3
51 43 *
52 - * @param $wp_admin_bar WP_Admin_Bar
44 + * @param $wp_admin_bar
53 45 */
54 46 function _mw_adminimize_add_logout( $wp_admin_bar ) {
55 47
56 48 $user_id = get_current_user_id();
57 49 $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
58 - $redirect = '';
59 50 if ( 1 === $_mw_adminimize_ui_redirect ) {
60 51 $redirect = '&amp;redirect_to=' . get_option( 'siteurl' );
52 + } else {
53 + $redirect = '';
61 54 }
62 55
63 56 if ( ! $user_id ) {
64 57 return;
@@ -73,32 +66,17 @@
73 66 )
74 67 );
75 68 }
76 69
77 -/**
78 - * Add stylesheet for see the the admin bar item also on mobile.
79 - */
80 -function _mw_adminimize_admin_bar_style() {
81 - ?>
82 - <style type="text/css">
83 - #wpadminbar #wp-admin-bar-mw-account { display: block; }
84 - </style>
85 - <?php
86 -}
87 -
88 -/**
89 - * Add Logout link include user info.
90 - *
91 - * @param $wp_admin_bar WP_Admin_Bar
92 - */
93 70 function _mw_adminimize_add_user_logout( $wp_admin_bar ) {
94 71
95 72 $user_id = get_current_user_id();
96 73 $current_user = wp_get_current_user();
97 74 $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
98 - $redirect = '';
99 75 if ( 1 === $_mw_adminimize_ui_redirect ) {
100 76 $redirect = '&amp;redirect_to=' . get_option( 'siteurl' );
77 + } else {
78 + $redirect = '';
101 79 }
102 80
103 81 if ( ! $user_id ) {
104 82 return;
@@ -115,30 +93,15 @@
115 93 )
116 94 );
117 95 }
118 96
119 -add_action( 'init', '_mw_adminimize_set_logout_menu', 2 );
120 -/**
121 - * Change logout, user info link in Admin bar.
122 - *
123 - * @return void
124 - */
125 -function _mw_adminimize_set_logout_menu() {
97 +function _mw_adminimize_set_menu_option_33() {
126 98
127 - if ( ! is_user_logged_in() ) {
128 - return;
129 - }
130 -
131 - // exclude super admin.
99 + // exclude super admin
132 100 if ( _mw_adminimize_exclude_super_admin() ) {
133 - return;
101 + return NULL;
134 102 }
135 103
136 - // Leave the settings screen from Adminimize to see all areas on settings.
137 - if ( _mw_adminimize_exclude_settings_page() ) {
138 - return;
139 - }
140 -
141 104 $user_roles = _mw_adminimize_get_all_user_roles();
142 105
143 106 foreach ( $user_roles as $role ) {
144 107 $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
@@ -148,10 +111,10 @@
148 111 'mw_adminimize_disabled_submenu_' . $role . '_items'
149 112 );
150 113 }
151 114
152 - $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
153 - // change user-info.
115 + $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
116 + // change user-info
154 117 switch ( $_mw_adminimize_user_info ) {
155 118 case 1:
156 119 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' );
157 120 break;
@@ -157,16 +120,12 @@
157 120 break;
158 121 case 2:
159 122 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' );
160 123 add_action( 'admin_bar_menu', '_mw_adminimize_add_logout', 0 );
161 - add_action( 'wp_head', '_mw_adminimize_admin_bar_style' );
162 - add_action( 'admin_head', '_mw_adminimize_admin_bar_style' );
163 124 break;
164 125 case 3:
165 126 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' );
166 127 add_action( 'admin_bar_menu', '_mw_adminimize_add_user_logout', 0 );
167 - add_action( 'wp_head', '_mw_adminimize_admin_bar_style' );
168 - add_action( 'admin_head', '_mw_adminimize_admin_bar_style' );
169 128 break;
170 129 }
171 130 }
172 131
@@ -171,94 +130,91 @@
171 130 }
172 131
173 132 /**
174 133 * Remove Admin Bar
175 - *
176 - * @return void
177 134 */
178 135 function _mw_adminimize_remove_admin_bar() {
179 136
180 - if ( ! is_user_logged_in() ) {
181 - return;
182 - }
183 -
184 - // exclude super admin.
137 + // exclude super admin
185 138 if ( _mw_adminimize_exclude_super_admin() ) {
186 - return;
139 + return NULL;
187 140 }
188 141
189 - // Leave the settings screen from Adminimize to see all areas on settings.
190 - if ( _mw_adminimize_exclude_settings_page() ) {
191 - return;
192 - }
142 + global $wp_version;
193 143
194 - $user_roles = _mw_adminimize_get_all_user_roles();
195 - $disabled_global_option_ = array();
144 + $user_roles = _mw_adminimize_get_all_user_roles();
196 145
197 146 foreach ( $user_roles as $role ) {
198 - $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
147 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
199 148 'mw_adminimize_disabled_global_option_' . $role . '_items'
200 149 );
201 150 }
202 151
203 - $mw_global_options = array();
204 - $user = wp_get_current_user();
152 + foreach ( $user_roles as $role ) {
153 + if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) {
154 + $disabled_global_option_[ $role ][ '0' ] = '';
155 + }
156 + }
205 157
158 + $remove_adminbar = FALSE;
159 + // new 1.7.8
206 160 foreach ( $user_roles as $role ) {
207 -
208 - if ( in_array( $role, $user->roles, true )
209 - && _mw_adminimize_current_user_has_role( $role )
210 - ) {
211 - // Create array about all items with all affected roles, important for multiple roles.
212 - foreach ( $disabled_global_option_[ $role ] as $global_item ) {
213 - $mw_global_options[] = $global_item;
161 + $user = wp_get_current_user();
162 + if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
163 + if ( _mw_adminimize_current_user_has_role( $role )
164 + && isset( $disabled_global_option_[ $role ] )
165 + && is_array( $disabled_global_option_[ $role ] )
166 + ) {
167 + if ( _mw_adminimize_recursive_in_array( '.show-admin-bar', $disabled_global_option_[ $role ] ) ) {
168 + $remove_adminbar = TRUE;
169 + }
214 170 }
215 171 }
216 172 }
217 173
218 - // Support Multiple Roles for users.
219 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
220 - $mw_global_options = _mw_adminimize_get_duplicate( $mw_global_options );
221 - }
222 -
223 - $remove_adminbar = false;
224 - // Check for admin bar selector to set to remove the Admin Bar.
225 - if ( _mw_adminimize_recursive_in_array( '.show-admin-bar', $mw_global_options ) ) {
226 - $remove_adminbar = true;
227 - }
228 -
229 174 if ( $remove_adminbar ) {
230 - if ( ! is_admin_bar_showing() ) {
231 - return;
232 - }
175 + // for deactivate admin bar in WP smaller WP 3.3
176 + if ( version_compare( $wp_version, '3.3alpha', '<=' ) ) {
177 + add_filter( 'show_admin_bar', '__return_false' );
178 + wp_deregister_script( 'admin-bar' );
179 + wp_deregister_style( 'admin-bar' );
180 + remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
181 + remove_action( 'wp_head', '_admin_bar_bump_cb' );
182 + } else {
183 + if ( ! is_admin_bar_showing() ) {
184 + return FALSE;
185 + }
233 186
234 - add_filter( 'show_admin_bar', '__return_false' );
235 - add_filter( 'wp_admin_bar_class', '__return_false' );
236 - add_filter( 'show_wp_pointer_admin_bar', '__return_false' );
237 - wp_deregister_script( 'admin-bar' );
238 - wp_deregister_style( 'admin-bar' );
239 - remove_action( 'init', '_wp_admin_bar_init' );
240 - remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
241 - remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
187 + add_filter( 'show_admin_bar', '__return_false' );
188 + add_filter( 'wp_admin_bar_class', '__return_false' );
189 + add_filter( 'show_wp_pointer_admin_bar', '__return_false' );
190 + wp_deregister_script( 'admin-bar' );
191 + wp_deregister_style( 'admin-bar' );
192 + remove_action( 'init', '_wp_admin_bar_init' );
193 + remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
194 + remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
242 195
243 - // maybe also: 'wp_head'.
244 - foreach ( array( 'wp_head', 'admin_head' ) as $hook ) {
245 - add_action(
246 - $hook,
247 - function() {
248 - echo '<style>body.admin-bar, body.admin-bar #wpcontent, body.admin-bar #adminmenu {
249 - padding-top: 0 !important;
250 - }
251 - html.wp-toolbar {
252 - padding-top: 0 !important;
253 - }</style>';
254 - }
255 - );
256 - }
196 + // maybe also: 'wp_head'
197 + foreach ( array( 'wp_head', 'admin_head' ) as $hook ) {
198 + add_action(
199 + $hook,
200 + create_function(
201 + '',
202 + "echo '<style>body.admin-bar, body.admin-bar #wpcontent, body.admin-bar #adminmenu {
203 + padding-top: 0 !important;
204 + }
205 + html.wp-toolbar {
206 + padding-top: 0 !important;
207 + }</style>';"
208 + )
209 + );
210 + }
257 211
258 - add_action( 'in_admin_header', '_mw_adminimize_restore_links' );
212 + add_action( 'in_admin_header', '_mw_adminimize_restore_links' );
213 + } // end else version 3.3
214 + } // end if $remove_adminbar TRUE
259 215
260 - } // end if $remove_adminbar TRUE
216 + return NULL;
261 217 }
262 218
263 219 /**
264 220 * Add Site Link in Menu
@@ -296,19 +252,17 @@
296 252 float: right;
297 253 }
298 254 </style>
299 255 <div id="mw_adminimize_admin_bar">
300 - <?php
301 - echo '<a id="mw_title" href="' . home_url() . '" title="' . esc_attr__(
302 - get_bloginfo( 'name' )
303 - ) . '" target="_blank">' . get_bloginfo( 'name' ) . '</a>';
256 + <?php echo '<a id="mw_title" href="' . home_url() . '" title="' . esc_attr__(
257 + get_bloginfo( 'name' )
258 + ) . '" target="_blank">' . get_bloginfo( 'name' ) . '</a>';
304 259 ?>
305 260 <div id="mw_adminimize_login">
306 261 <?php
262 + wp_get_current_user();
307 263 $current_user = wp_get_current_user();
308 - if ( empty( $_mw_adminimize_user_info ) || 0 === $_mw_adminimize_user_info
309 - || 3 === $_mw_adminimize_user_info
310 - ) {
264 + if ( empty( $_mw_adminimize_user_info ) || 0 === $_mw_adminimize_user_info || 3 === $_mw_adminimize_user_info ) {
311 265 if ( ! ( $current_user instanceof WP_User ) ) {
312 266 return;
313 267 }
314 268 echo ' ' . $current_user->user_login . ' ';
@@ -315,33 +269,25 @@
315 269
316 270 if ( is_multisite() && is_super_admin() ) {
317 271 if ( ! is_network_admin() ) {
318 272 echo '| <a href="' . network_admin_url() . '" title="' . esc_attr__(
319 - 'Network Admin'
320 - ) . '">' . esc_attr__( 'Network Admin' ) . '</a>';
273 + 'Network Admin'
274 + ) . '">' . esc_attr__( 'Network Admin' ) . '</a>';
321 275 } else {
322 276 echo '| <a href="' . get_dashboard_url( get_current_user_id() ) . '" title="' . esc_attr__(
323 - 'Site Admin'
324 - ) . '">' . esc_attr__( 'Site Admin' ) . '</a>';
277 + 'Site Admin'
278 + ) . '">' . esc_attr__( 'Site Admin' ) . '</a>';
325 279 }
326 280 }
327 281 }
328 282
329 - if ( empty( $_mw_adminimize_user_info ) || 0 === $_mw_adminimize_user_info
330 - || 2 === $_mw_adminimize_user_info
331 - || 3 === $_mw_adminimize_user_info
332 - ) {
333 - ?>
334 - |
335 - <?php
336 - echo '<a href="' . wp_logout_url() . '" title="' . esc_attr__(
283 + if ( empty( $_mw_adminimize_user_info ) || 0 == $_mw_adminimize_user_info || 2 == $_mw_adminimize_user_info || 3 == $_mw_adminimize_user_info ) {
284 + ?> | <?php echo '<a href="' . wp_logout_url() . '" title="' . esc_attr__( 'Log Out' ) . '">' . esc_attr__(
337 285 'Log Out'
338 - ) . '">' . esc_attr__(
339 - 'Log Out'
340 286 ) . '</a>';
341 287 }
342 288 ?>
343 289 </div>
344 290 </div>
345 - <?php
291 +<?php
346 292 }
347 293