array(), 'hide_item' => array(), 'show_above' => 0, 'adminbar_style' => 'none', 'adminbar_position' => 'start', 'inactive_opacity' => 100, 'inactive_size' => 34, 'animation_duration' => 200, 'mouseenter_delay' => 0, 'mouseleave_delay' => 1000, 'remove_admin_bar_class' => 0, ); $this->settings = get_option('admin_bar_settings'); if( is_array( $this->settings ) ){ $this->settings['hide_admin_bar'] = isset( $this->settings['hide_admin_bar'] ) ? (array)$this->settings['hide_admin_bar'] : $defaults['hide_admin_bar']; $this->settings['hide_item'] = isset( $this->settings['hide_item'] ) ? (array)$this->settings['hide_item'] : $defaults['hide_item']; $this->settings['show_above'] = isset( $this->settings['show_above'] ) ? intval( $this->settings['show_above'] ) : $defaults['show_above']; $this->settings['adminbar_style'] = isset( $this->settings['adminbar_style'] ) && in_array( $this->settings['adminbar_style'], $this->adminbar_styles ) ? esc_attr( $this->settings['adminbar_style'] ) : $defaults['adminbar_style']; $this->settings['adminbar_position'] = isset( $this->settings['adminbar_position'] ) ? esc_attr( $this->settings['adminbar_position'] ) : $defaults['adminbar_position']; $this->settings['inactive_opacity'] = isset( $this->settings['inactive_opacity'] ) ? intval( $this->settings['inactive_opacity'] ) : $defaults['inactive_opacity']; $this->settings['inactive_size'] = isset( $this->settings['inactive_size'] ) ? intval( $this->settings['inactive_size'] ) : $defaults['inactive_size']; $this->settings['animation_duration'] = isset( $this->settings['animation_duration'] ) ? intval( $this->settings['animation_duration'] ) : $defaults['animation_duration']; $this->settings['mouseenter_delay'] = isset( $this->settings['mouseenter_delay'] ) ? intval( $this->settings['mouseenter_delay'] ) : $defaults['mouseenter_delay']; $this->settings['mouseleave_delay'] = isset( $this->settings['mouseleave_delay'] ) ? intval( $this->settings['mouseleave_delay'] ) : $defaults['mouseleave_delay']; $this->settings['remove_admin_bar_class'] = isset( $this->settings['remove_admin_bar_class'] ) ? intval( $this->settings['remove_admin_bar_class'] ) : $defaults['remove_admin_bar_class']; }else{ $this->settings = $defaults; } // load textdomain for translations add_action( 'plugins_loaded', function(){ load_plugin_textdomain( 'admin_bar_fix', false, basename( dirname( __FILE__ ) ) . '/languages/' ); }); // disable 32px margin generated by WP add_action( 'after_setup_theme', function(){ if( $this->settings['adminbar_style'] != 'none' ){ remove_action( 'wp_head', '_admin_bar_bump_cb' ); add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) ); } }); // disable admin-bar body class add_filter( 'body_class', function( $classes ){ if( $this->settings['remove_admin_bar_class'] ){ if( ( $key = array_search( 'admin-bar', $classes ) ) !== false ){ unset( $classes[ $key ] ); } } return $classes; }, 9999 ); // setup plugins settings page add_action( 'admin_menu', array( $this, 'plugin_menu_link' ) ); // output CSS fixes add_action( 'wp_head', array( $this, 'advanced_admin_bar' ), PHP_INT_MAX ); } function advanced_admin_bar(){ if( ! is_user_logged_in() ) return; ob_start(); ?> html #wpadminbar{ overflow: hidden; } html #wpadminbar:hover{ overflow: visible; opacity: 1; } html #wp-toolbar, html #wp-toolbar > ul{ display: flex; flex-wrap: nowrap; height: 100%; min-width: 0; white-space: nowrap; } html #wp-toolbar > ul + ul{ margin-left: auto; } html #wp-toolbar > ul > li{ min-width: 0; } html #wp-toolbar > ul > li:hover{ flex-shrink: 0; } html #wp-toolbar > ul > li > a{ overflow: hidden; text-overflow: ellipsis; } html #wpadminbar:hover #wp-toolbar > ul > li{ min-width: 0; } html #wpadminbar .ab-top-menu > .menupop > .ab-sub-wrapper{ top: 100%; } settings['adminbar_style'] . '.php'; if( $this->settings['show_above'] ){ ?> @media (max-width: settings['show_above'] ) - 1 ?>px){ html #wpadminbar{ display: none !important; } }settings['hide_item'] ) ){ echo '#wp-admin-bar-' . implode( ',#wp-admin-bar-', array_map( 'esc_attr', $this->settings['hide_item'] ) ) . '{display:none}'; } $style = ob_get_clean(); $style = str_replace( array( "\t", "\r\n", "\n", "\r", ': ', ';}', ' > ', ' + ' ), array( '', '', '', '', ':', '}', '>', '+' ), $style ); if( count( $this->settings['hide_admin_bar'] ) ){ $user = wp_get_current_user(); $roles = (array)$user->roles; $hidden = true; foreach( $roles as $role ){ if( ! in_array( $role, $this->settings['hide_admin_bar'] ) ){ $hidden = false; break; } } if( $hidden ){ show_admin_bar( false ); }else{ echo ''; } }else{ echo ''; } } function plugin_menu_link(){ $this->plugin_admin_page = add_submenu_page( 'options-general.php', __( 'Admin Bar Fix', 'admin_bar_fix' ), __( 'Admin Bar Fix', 'admin_bar_fix' ), 'manage_options', basename( __FILE__ ), array( $this, 'admin_options_page' ) ); add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), function( $links ){ array_unshift( $links, '' . __('Settings') . '' ); return $links; }, 10, 1 ); } function admin_options_page(){ if( get_current_screen()->id != $this->plugin_admin_page ) return; global $wp_roles; if( isset( $_POST['plugin_sent'] ) && check_admin_referer('abf_settings') ){ $hide_admin_bar = array(); if( isset( $_POST['hide_admin_bar'] ) && is_array( $_POST['hide_admin_bar'] ) ){ foreach( $_POST['hide_admin_bar'] as $role ){ $hide_admin_bar[] = sanitize_text_field( $role ); } } $hide_item = array(); if( isset( $_POST['hide_item'] ) && is_array( $_POST['hide_item'] ) ){ foreach( $_POST['hide_item'] as $item ){ $hide_item[] = sanitize_text_field( $item ); } } $this->settings = array( 'hide_admin_bar' => $hide_admin_bar, 'hide_item' => $hide_item, 'show_above' => intval( $_POST['show_above'] ), 'adminbar_style' => in_array( $_POST['adminbar_style'], $this->adminbar_styles ) ? sanitize_text_field( $_POST['adminbar_style'] ) : 'none', 'adminbar_position' => sanitize_text_field( $_POST['adminbar_position'] ), 'inactive_opacity' => intval( $_POST['inactive_opacity'] ), 'inactive_size' => intval( $_POST['inactive_size'] ), 'animation_duration' => intval( $_POST['animation_duration'] ), 'mouseenter_delay' => intval( $_POST['mouseenter_delay'] ), 'mouseleave_delay' => intval( $_POST['mouseleave_delay'] ), 'remove_admin_bar_class' => isset( $_POST['remove_admin_bar_class'] ) ? 1 : 0, ); update_option( 'admin_bar_settings', $this->settings ); } ?>

' . __('Settings saved.') . '

' ?>
  roles as $role_slug => $role ){ $role_slug = esc_attr( $role_slug ); echo '
'; } ?>
  settings['hide_item'] ) ? ' checked' : '' ) . ' name="hide_item[]" value="' . esc_attr( $item ) . '">' . esc_html( $item ) . '
'; } ?>
 
  px
  %
  px

  ms
  ms
  ms