How to hide Appointment fields in admin section from non admins

The only screen users are allowed to see in my install is the Appointments, /admin.php?page=appointments

I’m using code from https://premium.wpmudev.org/forums/topic/appointment-hiding-the-visibility-of-certain-aspects-of-the-backend to limit what information can be seen.

All the fields I want are hidden, but they’re hidden from me too. I want to still be able to see everything, but hide it from all the other (non admin) users.

I’ve seen this snippet
if(!current_user_can('administrator’)) {
I just don’t know how to combine it with my code. Can someone help?

This is what I have so far:

add_action( 'admin_head', 'wpmu_5433_custom_admin_css' );
function wpmu_5433_custom_admin_css(){ ?>
     <style>
          .search-form .tabletopnav.top {
               display: none !important;
          }
          .search-form .search-box {
               display: none !important;
          }
          .subsubsub > li:nth-of-type(6) {
               display: none !important;
          }
          .subsubsub > li:nth-of-type(4) {
               display: none !important;
          }
          body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:last-child, body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-center .inline-edit-col > label:last-child {
               display: none;
          }
          body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:first-of-type, body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:first-of-type{
               display: none;
          }
          body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:last-child, body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-center .inline-edit-col {
               display: none;
          }
          body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left {
               width: 49% !important;
               }
          body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-right {
               width: 49% !important;
               }
          body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:first-child {
               display: none !important;
          }
     </style>
<?php
}

Thank you

  • Sohag Ronjon Dey

    Hi Wendy,

    Hope you are doing well! :slight_smile:

    I think you have done all the hard parts yourself. Just add the condition like the following.

    add_action( 'admin_head', 'wpmu_5433_custom_admin_css' );
    function wpmu_5433_custom_admin_css(){
    	if(!current_user_can('administrator')) {
    ?>
         <style>
              .search-form .tabletopnav.top {
                   display: none !important;
              }
              .search-form .search-box {
                   display: none !important;
              }
              .subsubsub > li:nth-of-type(6) {
                   display: none !important;
              }
              .subsubsub > li:nth-of-type(4) {
                   display: none !important;
              }
              body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:last-child, body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-center .inline-edit-col > label:last-child {
                   display: none;
              }
              body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:first-of-type, body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:first-of-type{
                   display: none;
              }
              body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:last-child, body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-center .inline-edit-col {
                   display: none;
              }
              body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left {
                   width: 49% !important;
                   }
              body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-right {
                   width: 49% !important;
                   }
              body.toplevel_page_appointments table.appointments #the-list .inline-edit-col-left .inline-edit-col > label:first-child {
                   display: none !important;
              }
         </style>
    <?php
    	}
    }

    add the code in the functions.php file in your active theme

    Suppose you have activated the twentyseventeen theme then you will find the functions.php file in twentyseventeen directory like

    main wordpress directory
    |---wp-admin
    |---wp-includes
    |---wp-content
    |    |---plugins
    |    |---themes
    |    |    |---twentyfifteen
    |    |    |---twentyseventeen
    |    |    |   |---functions.php

    Hope this helps.

    Please let us know if you need any further help.

    Cheers,
    Sohag.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.