PluginProbe
Adminimize / 1.11.3
Adminimize v1.11.3
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
adminimize / inc-setup / remove-admin-bar.php

remove-admin-bar.php in Adminimize 1.11.3, at inc-setup/remove-admin-bar.php

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