Is there any way to hide tabs on settings pages

Support MB Settings Page Is there any way to hide tabs on settings pages

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33790
    dom@viewtolearn.co.uk[email protected]
    Participant

    Hi

    I have searched the documentation and read dozens of posts on the forum but cannot find out if there is a way to successfully control the visibility of tabs on a settings page.

    I should state at the outset that the settings page is being used within a plugin that I am developing. Ideally I would like the first tab to act as a 'control panel' for those that follow.

    I thought that I had found a potential solution with this tutorial https://docs.metabox.io/hide-tabs-with-conditional-logic/ but the classes that MetaBox produces in the output HTML do not seem to match expectations.

    For example this code defines the tabs;

    add_filter(
     'mb_settings_pages',
     function ($settings_pages) {
      $settings_pages[] = array(
       'id'          => 'vtl_site_options',
       'option_name' => 'vtl_site_options',
       'menu_title'  => 'Site Options',
       'position'    => 1,
       'icon_url'    => 'data:image/svg',
       'tabs'        => array(
        'site_colours'         => 'Site Colours',
        'backup_site_settings' => 'Backup',
       ),
       'tab_style'   => 'left',
      );
      return $settings_pages;
     }
    );

    And the output HTML looks like this,

    <h2 class="nav-tab-wrapper>
        <a href="#tab-site_colours">Site Colours></a>
        <a href="#tab-backup_site_settings">Backup</a>
        ::after
    </h2>

    So unless I've missed something it's not producing meaningful class names we can use in any conditional logic.

    I'm getting the impression that what I'd like to do isn't doable, but if it is could you possibly provide an example please.

    Many/h2&gt thanks.

    #33806
    Long NguyenLong Nguyen
    Moderator

    Hi Dom,

    You can use the CSS/JS attribute selector to select the tab with anchor tab ID. Like this

    add_filter( 'rwmb_outside_conditions', function( $conditions ) {
        $conditions['a[href="#tab-backup_site_settings"'] = array(
            'hidden' => ['#text', '123'],
        );
        return $conditions;
    } );

    Read more on this tutorial https://www.w3schools.com/css/css_attribute_selectors.asp

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.