Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Remove tabs and fields for roles

  • Hi,

    I know this is an old topic, I have found many threads here, but some just pointed in the general direction of somewhere WordPress, and actual code that was given did not work. Perhaps because those posts were too old. Those were all about metaboxes, and I guess those are now panels and meta fields in Gutenberg. So perhaps this isn’t even a GeneratePress question, although I’d like to hide GP controls in particular.

    What I need, is to remove some of the tabs and fields for roles other than admin. Not everything, just the layout tab, for example, or “object fit” in the image block settings.

    Theoretically one could just hide those fields with CSS:

    function hide_meta_boxes(){if(!current_user_can('administrator')) { /* hide beckground color setting */
    echo '<style>.components-tools-panel-item.block-editor-tools-panel-color-gradient-settings__item.last { display: none !important; }</style>'; }}
    add_action('admin_head', 'hide_meta_boxes');

    But is that the best way?

    Thanks!

    EDIT: I now looked at the editor source, and found why CSS is no good. None of the boxes have safe classes to access them. GP panels all have the same class: components-panel__body gblocks-panel-label
    Even elements inside the panel have no unique classes. The only way I see is nth-child(). But if anything ever changes in the panel order, the CSS will break.

  • Hi there,

    just so I am clear – you want to remove some of the settings available in some of the blocks in the Gutenberg editor ?

    IF so, are those the core WordPress blocks ?

  • Thanks for the quick reply!

    Yes. Mostly GP blocks. Perhaps default blocks, too. But the default blocks are normally much less powerful, less confusing for beginners and messing with them causes less damage.
    It’s also about tabs. Editors do not need to do anything with the GP Layout tab, e.g.

  • It’s not possible at the moment, once we have GB 2.0 out in the wild which has a new styles search and filter, we will be looking at filters to do just what you need.

  • Thanks, David. Great that you have it on the list, I’m looking forward to it!

  • You’re welcome!

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