<?php
/* ========================================================== */
/* Alterar Texto do Footer Admin */
/* ========================================================== */
function left_admin_footer_text_output($text)
{
  return 'Desenvolvido por' . ' <a href="https://www.oxigenweb.com.br" title="' . 'Criação de sites em wordpress' . '" target="_blank">' . 'OxigenWeb' . '</a>';
}
add_filter('admin_footer_text', 'left_admin_footer_text_output');

function right_admin_footer_text_output($text)
{
  return "";
}
add_filter('update_footer', 'right_admin_footer_text_output', 11);

/* ========================================================== */
/* Alterar Imagem, Title e Link do Login */
/* ==========================================================  */
function login_logo()
{ ?>
  <style type="text/css">
    .login {
      position: relative;
      overflow-y: auto;
      background: linear-gradient(270deg, #1D9E9A 0%, #103351 100%);
    }

    .login a {
      color: white !important;
    }

    .login h1 a {
      background-image: url("<?php bloginfo('template_url') ?>/assets/images/logo-esg.svg") !important;
      background-size: 150px !important;
      width: 100% !important;
      height: 87px !important;
    }
  </style>
<?php
}
add_action('login_head', 'login_logo');

/* ========================================================== */
/* Remover Itens da barra de Admin */
/* ========================================================== */
function wps_admin_bar()
{
  global $wp_admin_bar;
  $wp_admin_bar->remove_menu('wp-logo');
  if (!current_user_can('edit_users')) {
    $wp_admin_bar->remove_menu('about');
    $wp_admin_bar->remove_menu('wporg');
    $wp_admin_bar->remove_menu('documentation');
    $wp_admin_bar->remove_menu('support-forums');
    $wp_admin_bar->remove_menu('feedback');
    $wp_admin_bar->remove_menu('view-site');
    $wp_admin_bar->remove_menu('comments');
    $wp_admin_bar->remove_menu('new-content');
    $wp_admin_bar->remove_menu('new-post');
    $wp_admin_bar->remove_menu('new-media');
    $wp_admin_bar->remove_menu('new-link');
    $wp_admin_bar->remove_menu('new-page');
    $wp_admin_bar->remove_menu('wpseo-menu');
  }
}
add_action('wp_before_admin_bar_render', 'wps_admin_bar');

/* ========================================================== */
/* Customiza a visualização da barra de admin */
/* ========================================================== */
function o2_admin_bar()
{ ?>
  <!-- BARRA DE ADMIN -->
  <div id="o2-admin-bar-wrapper" class="d-none d-md-block">
    <div class="d-flex align-items-center">
      <span style="font-size: 30px;" class="dashicons dashicons-admin-tools"></span>
    </div>
    <div class="" id="o2-admin-bar"></div>
  </div>
  <script>
    document.addEventListener('DOMContentLoaded', function() {
      jQuery('#wpadminbar').appendTo('#o2-admin-bar');
      jQuery('html').addClass('m-0');
    });
  </script>
<?php
}

function o2_admin_bar_style()
{?>
  <style>
    #o2-admin-bar-wrapper {
      position: fixed;
      z-index: 99999;
      width: 33px;
      height: 32px;
      left: 0;
      top: 20%;
      border-radius: 0 5px 5px 0;
      background: #65D98B;
    }

    #o2-admin-bar-wrapper * {
      color: #fff;
    }

    #o2-admin-bar-wrapper #o2-admin-bar {
      display: none;
    }

    #o2-admin-bar-wrapper:hover {
      width: 210px;
    }

    #o2-admin-bar-wrapper:hover #o2-admin-bar {
      display: block;
    }

    #o2-admin-bar {
      background: #65D98B;
    }

    #o2-admin-bar #wpadminbar {
      margin-top: 12px;
      min-width: 210px;
      max-width: 210px;
      position: relative;
      height: fit-content;
    }

    #o2-admin-bar #wpadminbar .ab-top-menu,
    #o2-admin-bar #wpadminbar .ab-top-menu {
      display: flex;
      flex-direction: column;
    }

    #o2-admin-bar #wpadminbar .ab-submenu {
      width: 210px;
    }

    #o2-admin-bar #wpadminbar #adminbarsearch {
      display: none;
    }

    #o2-admin-bar #wpadminbar .menupop.hover .ab-sub-wrapper {
      top: 0;
      left: 100%;
      min-width: 210px;
    }

    #o2-admin-bar #wpadminbar .menupop.hover .ab-sub-wrapper .ab-sub-wrapper {
      left: 0;
    }

    #o2-admin-bar #wpadminbar #wp-admin-bar-top-secondary {
      position: absolute;
      top: -32px;
      left: 33px;
      width: 177px;
    }

    #o2-admin-bar #wpadminbar #wp-admin-bar-top-secondary .admin-bar-search {
      height: 0;
    }
  </style>
<?php
}

if (is_admin_bar_showing()) {
  add_action('wp_head', 'o2_admin_bar_style');
  add_action('wp_footer', 'o2_admin_bar');
}