PluginProbe
Admin and Site Enhancements (ASE) / 7.8.12
Admin and Site Enhancements (ASE) v7.8.12
9.1.1 9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 All 273 releases
admin-site-enhancements / classes / class-hide-admin-bar.php
class-hide-admin-bar.php
55 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class for Hide Admin Bar module
7 *
8 * @since 6.9.5
9 */
10 class Hide_Admin_Bar {
11 /**
12 * Hide admin bar on the frontend for the user roles selected
13 *
14 * @since 1.3.0
15 */
16 public function hide_admin_bar_for_roles_on_frontend() {
17 $options = get_option( ASENHA_SLUG_U );
18 $hide_admin_bar = $options['hide_admin_bar'];
19 $for_roles_frontend = $options['hide_admin_bar_for'];
20 $always_show_for_admins_on_frontend = ( isset( $options['hide_admin_bar_always_show_for_admins'] ) ? $options['hide_admin_bar_always_show_for_admins'] : false );
21 $current_user = wp_get_current_user();
22 $current_user_roles = (array) $current_user->roles;
23 // single dimensional array of role slugs
24 // User has no role, i.e. logged-out
25 if ( count( $current_user_roles ) == 0 ) {
26 return false;
27 // hide admin bar
28 }
29 // User has role(s). Do further checks.
30 // Maybe show admin bar if user is an administrator
31 if ( in_array( 'administrator', $current_user_roles ) && $always_show_for_admins_on_frontend ) {
32 return true;
33 }
34 if ( isset( $for_roles_frontend ) && count( $for_roles_frontend ) > 0 ) {
35 // Assemble single-dimensional array of roles for which admin bar would be hidden
36 $roles_admin_bar_hidden_frontend = array();
37 foreach ( $for_roles_frontend as $role_slug => $admin_bar_hidden ) {
38 if ( $admin_bar_hidden ) {
39 $roles_admin_bar_hidden_frontend[] = $role_slug;
40 }
41 }
42 // Check if any of the current user roles is one for which admin bar should be hidden
43 foreach ( $current_user_roles as $role ) {
44 if ( in_array( $role, $roles_admin_bar_hidden_frontend ) ) {
45 return false;
46 // hide admin bar
47 }
48 }
49 }
50 return true;
51 // show admin bar
52 }
53
54 }
55