Community Forums › Forums › Archived Forums › Design Tips and Tricks › php function to remove (hide) menu items from "Editor" dashboard
Tagged: customize dashboard, php function
- This topic has 6 replies, 3 voices, and was last updated 4 years, 11 months ago by
andytc.
-
AuthorPosts
-
February 11, 2021 at 2:17 pm #503005
danielleB
ParticipantUnfortunately 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,
https://tdspontiac.orgDanielle
February 11, 2021 at 4:51 pm #503010AnitaC
KeymasterI'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.
Need help with customization or troubleshooting? Reach out to me.
February 12, 2021 at 5:34 am #503021andytc
ParticipantKeeping 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 #503024danielleB
ParticipantThank you, Andy. I owe you a coffee.
Danielle
Danielle
February 12, 2021 at 8:43 am #503025danielleB
ParticipantThis reply has been marked as private.February 12, 2021 at 8:47 am #503026AnitaC
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.
Need help with customization or troubleshooting? Reach out to me.
February 12, 2021 at 9:00 am #503028andytc
ParticipantYou’re welcome , I’m happy it’s what you wanted.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.