• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

php function to remove (hide) menu items from "Editor" dashboard

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › php function to remove (hide) menu items from "Editor" dashboard

This topic is: not resolved

Tagged: customize dashboard, php function

  • This topic has 6 replies, 3 voices, and was last updated 1 year, 11 months ago by andytc.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • February 11, 2021 at 2:17 pm #503005
    danielleB
    Participant

    Unfortunately I'm not a fluent in php syntax, but I did find a little bit of code online that allowed me to add the 'appearance' menu $capability to the Editor dashboard.

    // Add 'appearance' capabilities to editors.
    $editor = get_role('editor');
    // add $cap capability to this role object
    $editor->add_cap('edit_theme_options');

    This worked fine, but I need to remove or hide sub-items from 'Appearance'. I only want to give Editors access to 'Menus' and 'Widgets' sub-items. I did find a lot of code to globally remove sub-items, but I only want to remove them from the Editor role, and all that I've tried has crashed the site. Would anyone have snippets of code that I could use as a guide? Or a link to help on this issue?

    Many thanks,


    Danielle

    https://tdspontiac.org
    February 11, 2021 at 4:51 pm #503010
    Anita
    Keymaster

    I'd use a plugin like User Role Editor for something like that - https://wordpress.org/plugins/user-role-editor/.

    Tinkering around in the functions file for things like that could be harmful.


    Love coffee, chocolate and my Bella!

    February 12, 2021 at 5:34 am #503021
    andytc
    Participant

    Keeping the code in place that you've used to change the capability for editors , you can add this to remove > Themes and the Customiser.

    // NON ADMIN ROLE APPEARENCE MENU EDITS
    
    if ( ! current_user_can('manage_options') ) {
    
    	// Remove submenu pages for non admins.
    	function wpdocs_adjust_the_wp_menu() {
    	  $page = remove_submenu_page( 'themes.php', 'themes.php' );
    	}
    
    	add_action( 'admin_menu', 'wpdocs_adjust_the_wp_menu', 999 );
    
    	// Remove the customsier
    	add_filter('map_meta_cap', function($caps, $cap, $user_id, $args) {
    	    if ('customize' == $cap) return ['do_not_allow'];
    	    return $caps;
    	}, 10, 4);
    
    }
    February 12, 2021 at 8:41 am #503024
    danielleB
    Participant

    Thank you, Andy. I owe you a coffee.

    Danielle


    Danielle

    February 12, 2021 at 8:43 am #503025
    danielleB
    Participant
    This reply has been marked as private.
    February 12, 2021 at 8:47 am #503026
    Anita
    Keymaster

    @danielleb You marked your message Private so I can only see it. But to answer your question, for me personally, adding things that control the dashboard functionality has always scared me. Not to mention that if you change themes or if the customer decided to change themes later on, that functionality will be lost if you don't remember to add it to the new theme. Or you can use a functionality plugin.


    Love coffee, chocolate and my Bella!

    February 12, 2021 at 9:00 am #503028
    andytc
    Participant

    You’re welcome , I’m happy it’s what you wanted.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble