HIde Appointments tabs from non super admin

Can you provide a script to hide tabs in settions for non superadmin users on multisite?

Example, addons, logs, etc

All i want to display working hours, general

  • geo1243
    • WPMU DEV Initiate

    Thank you for the reply…. Below is the answer i received from your team, David.

    I would really appreciate if you dev team can get back on a script fto implement the hook below…

    This feature is very important to me and holts me back on using on my multisite…

    Thanks!

    $tabs = apply_filters( ‘appointments_tabs’, $tabs );

    The PayPal options would require something more extensive, or it could be easily hidden using admin-side CSS.

    Sorry if that all sounds technical, I just wanted to be sure you’re aware of how it can be handled. We can assist with these types of things through our support forums too.

    Would that be viable for you?

  • DavidM
    • DEV MAN’s Mascot

    Hey @geo1243,

    Hope you’re doing well today! :slight_smile:

    You should be able to use code like so to remove specific tabs:

    function apps_remove_tabs( $tabs ) {
    if ( !is_super_admin() ) {
    unset( $tabs['gcal'] );
    }
    add_filter( 'appointments_tabs', 'apps_remove_tabs', 10, 1 );

    That’s probably best added as a new plugin using this as reference:

    http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information

    Then you can simply network activate it to automatically remove tabs across the multisite.

    The tab values you can remove are as follows:

    ‘gcal’

    ‘working_hours’

    ‘exceptions’

    ‘services’

    ‘workers’

    ‘addons’

    ‘log’

    Could you let us know how that works for ya?

    [EDIT: the snippet’s been updated due to some formatting issues]

    Cheers,

    David

  • geo1243
    • WPMU DEV Initiate

    David this is the script you sent over email. It differst from the one above, can you send me a script which works?

    thanks!!

    function apps_remove_tabs( $tabs ) {

    if ( ?!is_super_admin?() ) {

    ?unset( $tabs['gcal'] );

    ?}

    add_filter(? 'apps_remove_tabs', $tabs );

  • DavidM
    • DEV MAN’s Mascot

    Hey @geo1243,

    Sorry if you had any trouble with that, there were some formatting issues when I posted that initially so I edited it right away but it seems you copied that before the edit.

    The edited version above should work just fine, I’ll copy that here:

    function apps_remove_tabs( $tabs ) {
    if ( !is_super_admin() ) {
    unset( $tabs['gcal'] );
    }
    }
    add_filter( 'appointments_tabs', 'apps_remove_tabs', 10, 1 );

    Could you let us know how that works for you?

    Cheers,

    David

  • geo1243
    • WPMU DEV Initiate

    The error is: “Parse error: syntax error, unexpected end of file …” i think you missed “}”

    Also, can you post full script to hide all except working hours and services tab?

    thanks!

    if i post the script below, it gives me an error: “Warning: Invalid argument supplied for foreach() in”

    function apps_remove_tabs( $tabs ) {

    if ( !is_super_admin() ) {

    unset( $tabs );

    }

    }

    add_filter( ‘appointments_tabs’, ‘apps_remove_tabs’, 10, 1 );

  • aristath
    • Recruit

    Hello again @geo1243, I hope you’re well today!

    The error is: “Parse error: syntax error, unexpected end of file …” i think you missed “}”

    You’re absolutely right, sorry about that.. I have now edited the above post and fixed it. :slight_smile:

    if i post the script below, it gives me an error: “Warning: Invalid argument supplied for foreach() in”

    Could you please post the entire message you’re getting?

    Please advise,

    Ari.

  • lucas
    • New Recruit

    Hi

    right now i try to implement that code into my theme, but i run to a problem,

    if i ut this function inside function.php i run to an error in admin panel:

    Warning: Invalid argument supplied for foreach() in /wp-content/plugins/appointments/admin/class-app-admin.php on line 809

    and only general tab is visible

  • Kieran
    • The Crimson Coder

    Hi

    Rather coincidentally I was coming online to ask almost the same question. +1 for this. I ideally want just the appointments tab showing too but further restricted to be filtered by a service provider of my choosing depending on which user logs in.

    So my service providers can log in and create / remove their own appointments in the back end and export all their appointments. Basically save me the hassle and they can’t alter the settings pages

    Is it possible? Happy to create a new thread but looks like we want something very similar.

  • David @ BBS
    • Site Builder, Child of Zeus

    I needed to implement this on our site and didn’t find a solution posted anywhere on the forums so I figured I’d post the fully working code that I put together.

    // Remove unnecessary Tabs from Appointments Settings page for non-admin users
    function remove_extra_tabs_on_appointment_settings_admin_page($tabs){
    if(!current_user_can('administrator')) {
    $tabs_to_unset = array( 'main', 'gcal', 'services', 'addons', 'logs' );
    foreach ( $tabs_to_unset as $key ) {
    unset( $tabs[ $key ] );
    }
    }
    return $tabs;
    }
    add_filter('appointments_tabs', 'remove_extra_tabs_on_appointment_settings_admin_page', 20 );

    Place this in your theme’s functions.php file and modify the list of tabs you want to remove. Notice the $tabs_to_unset array includes a list of comma separated and single-quoted tab names. Your options are:

    ‘main’ => General

    ‘working_hours’ => Working Hours

    ‘gcal’ => Google Calendar

    ‘exceptions’ => Exceptions

    ‘services’ => Services

    ‘workers’ => Service Providers

    ‘addons’ => Add-ons

    ‘log’ => Logs

    In my case I’m removing the various tabs for any user who has access to the Appointments+ Settings page but is not an administrator.

    Hope this helps anyone else who has been looking for a solution!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.