PluginProbe
Adminimize / 1.11.10
Adminimize v1.11.10
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.10, at inc-setup/remove-admin-bar.php

348 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions to remove the admin bar.
4 *
5 * @package Adminimize
6 * @subpackage Remove Admin Bar of > WP 3.3 Setup
7 * @author Frank Bültge
8 */
9
10 if ( ! function_exists( 'add_action' ) ) {
11 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
12 exit;
13 }
14
15 // on init of WordPress.
16 add_action( 'init', '_mw_adminimize_remove_admin_bar', 0 );
17
18 /**
19 * Change the var of Admin Bar in WP 3.3
20 *
21 * @param array $admin_bar_keys
22 */
23 function _mw_adminimize_customize_admin_bar( array $admin_bar_keys ) {
24
25 if ( ! is_admin_bar_showing() ) {
26 return;
27 }
28
29 /**
30 * Reference to the doc to know the method.
31 *
32 * @var \WP_Admin_Bar $wp_admin_bar
33 */
34 global $wp_admin_bar;
35
36 foreach ( $admin_bar_keys as $key ) {
37 $wp_admin_bar->remove_menu( $key );
38 }
39 }
40
41 /**
42 * Remove my account item in admin bar >3.3
43 */
44 function _mw_adminimize_remove_my_account() {
45
46 _mw_adminimize_customize_admin_bar( array( 'my-account' ) );
47 }
48
49 /**
50 * Add Logout link to admin abr in wp 3.3
51 *
52 * @param $wp_admin_bar WP_Admin_Bar
53 */
54 function _mw_adminimize_add_logout( $wp_admin_bar ) {
55
56 $user_id = get_current_user_id();
57 $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
58 $redirect = '';
59 if ( 1 === $_mw_adminimize_ui_redirect ) {
60 $redirect = '&amp;redirect_to=' . get_option( 'siteurl' );
61 }
62
63 if ( ! $user_id ) {
64 return;
65 }
66
67 $wp_admin_bar->add_menu(
68 array(
69 'id' => 'mw-account',
70 'parent' => 'top-secondary',
71 'title' => esc_attr__( 'Log Out' ),
72 'href' => wp_logout_url() . $redirect,
73 )
74 );
75 }
76
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 function _mw_adminimize_add_user_logout( $wp_admin_bar ) {
94
95 $user_id = get_current_user_id();
96 $current_user = wp_get_current_user();
97 $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
98 $redirect = '';
99 if ( 1 === $_mw_adminimize_ui_redirect ) {
100 $redirect = '&amp;redirect_to=' . get_option( 'siteurl' );
101 }
102
103 if ( ! $user_id ) {
104 return;
105 }
106
107 $user_info = $current_user->display_name;
108
109 $wp_admin_bar->add_menu(
110 array(
111 'id' => 'mw-account',
112 'parent' => 'top-secondary',
113 'title' => $user_info . ' ' . esc_attr__( 'Log Out' ),
114 'href' => wp_logout_url() . $redirect,
115 )
116 );
117 }
118
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() {
126
127 if ( ! is_user_logged_in() ) {
128 return;
129 }
130
131 // exclude super admin.
132 if ( _mw_adminimize_exclude_super_admin() ) {
133 return;
134 }
135
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 $user_roles = _mw_adminimize_get_all_user_roles();
142
143 foreach ( $user_roles as $role ) {
144 $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
145 'mw_adminimize_disabled_menu_' . $role . '_items'
146 );
147 $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
148 'mw_adminimize_disabled_submenu_' . $role . '_items'
149 );
150 }
151
152 $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
153 // change user-info.
154 switch ( $_mw_adminimize_user_info ) {
155 case 1:
156 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' );
157 break;
158 case 2:
159 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' );
160 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 break;
164 case 3:
165 add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' );
166 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 break;
170 }
171 }
172
173 /**
174 * Remove Admin Bar
175 *
176 * @return void
177 */
178 function _mw_adminimize_remove_admin_bar() {
179
180 if ( ! is_user_logged_in() ) {
181 return;
182 }
183
184 // exclude super admin.
185 if ( _mw_adminimize_exclude_super_admin() ) {
186 return;
187 }
188
189 // Leave the settings screen from Adminimize to see all areas on settings.
190 if ( _mw_adminimize_exclude_settings_page() ) {
191 return;
192 }
193
194 $user_roles = _mw_adminimize_get_all_user_roles();
195 $disabled_global_option_ = array();
196
197 foreach ( $user_roles as $role ) {
198 $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
199 'mw_adminimize_disabled_global_option_' . $role . '_items'
200 );
201 }
202
203 $mw_global_options = array();
204 $user = wp_get_current_user();
205
206 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;
214 }
215 }
216 }
217
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 if ( $remove_adminbar ) {
230 if ( ! is_admin_bar_showing() ) {
231 return;
232 }
233
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 );
242
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 }
257
258 add_action( 'in_admin_header', '_mw_adminimize_restore_links' );
259
260 } // end if $remove_adminbar TRUE
261 }
262
263 /**
264 * Add Site Link in Menu
265 */
266 function _mw_adminimize_restore_links() {
267
268 $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
269 ?>
270 <style type="text/css">
271 #mw_adminimize_admin_bar {
272 left: 0;
273 right: 0;
274 height: 33px;
275 z-index: 999;
276 border-bottom: 1px solid #dfdfdf;
277 }
278
279 #mw_adminimize_admin_bar #mw_title {
280 font-family: Georgia, "Times New Roman", Times, serif;
281 font-size: 16px;
282 color: #464646;
283 text-decoration: none;
284 padding-top: 8px;
285 display: block;
286 float: left;
287 }
288
289 #mw_adminimize_admin_bar #mw_title:hover {
290 text-decoration: underline;
291 }
292
293 #mw_adminimize_admin_bar #mw_adminimize_login {
294 padding: 8px 15px 0 0;
295 display: block;
296 float: right;
297 }
298 </style>
299 <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>';
304 ?>
305 <div id="mw_adminimize_login">
306 <?php
307 $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 ) {
311 if ( ! ( $current_user instanceof WP_User ) ) {
312 return;
313 }
314 echo ' ' . $current_user->user_login . ' ';
315
316 if ( is_multisite() && is_super_admin() ) {
317 if ( ! is_network_admin() ) {
318 echo '| <a href="' . network_admin_url() . '" title="' . esc_attr__(
319 'Network Admin'
320 ) . '">' . esc_attr__( 'Network Admin' ) . '</a>';
321 } else {
322 echo '| <a href="' . get_dashboard_url( get_current_user_id() ) . '" title="' . esc_attr__(
323 'Site Admin'
324 ) . '">' . esc_attr__( 'Site Admin' ) . '</a>';
325 }
326 }
327 }
328
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__(
337 'Log Out'
338 ) . '">' . esc_attr__(
339 'Log Out'
340 ) . '</a>';
341 }
342 ?>
343 </div>
344 </div>
345 <?php
346 }
347
348