- This topic has 20 replies, 2 voices, and was last updated 1 year, 2 months ago by Leo.
-
AuthorPosts
-
May 22, 2017 at 1:54 pm #322461Dan
Hi. I found this plugin to give an Editor user access to Widgets and Menu under the Appearance menu on the Dashboard. However, it also gives them access to the GeneratePress option under the Appearance menu. Is there a way to easily hide this from the Editor? Or is there another plugin/way that anyone knows about to enable or disable certain areas the users can get to in the Dashboard?
May 22, 2017 at 8:20 pm #322615TomLead DeveloperLead DeveloperBy default users should only be able to see the GP Dashboard if they have the edit_theme_options capability, which is typically reserved for admins.
You can remove the menu item like this: https://gist.github.com/generatepress/a15f0cb00c90f218d04d802c0178bf5c
You can wrap that in a conditional if you want to hide it from specific users/capabilities.
Let me know if you need more info ๐
May 23, 2017 at 12:25 am #322669DanHey Tom. Thanks for the reply. So I’m not very good at Javascript, and by not good, I mean I really don’t know much of anything. When you say wrap that in a conditional, I don’t even know where to start. Sorry for my ignorance, but CSS is more my thing. (I think I need to go take a class in Java one of these days.) The plugin I spoke of earlier is called Editor Menu and Widget Access. It gives the ability to share just the Customize, Menu and Widget section of the Appearance part of the Dashboard with the Editor with also having the ability to turn any of those off as well. Nice feature, and it would be nice if WP just added that ability to their core. Alas, we need a plugin for that. Anyway, long story made longer, could you explain how I would wrap your code to make that effective only for Editor roles? And I assume I would put this in the functions.php file, correct? Sorry if I’m being a pain, but thanks again.
May 23, 2017 at 8:08 am #322887TomLead DeveloperLead DeveloperHmm, it sounds like that plugin is doing something wrong then, as it’s giving the editor the edit_theme_options capability.
You could try this:
add_action( 'wp','tu_remove_gp_admin_menu' ); function tu_remove_gp_admin_menu() { if ( ! current_user_can( 'manage_network' ) ) { remove_action('admin_menu', 'generate_create_menu'); remove_action( 'admin_menu', 'generate_do_dashboard_menu' ); } }
July 20, 2017 at 12:38 pm #352416DanHi Tom. I’m so sorry for the delay. I was wondering if I could pick your brain again about this now that I am able to revisit the issue. (Life happened) So, you are correct that the plugin is giving the edit_theme_options capability, but only to the Widgets, Menus, and GeneratePress. And I haven’t even tried this code yet because I don’t really know where to put it. Maybe the functions.php file? That said, do you know if the code above would work to turn that GeneratePress off for Editors only or would it have to be for something like current_user(‘editor’). I don’t even know if that’s a real thing. Thanks, and again, sorry for the delay.
July 20, 2017 at 7:35 pm #352534TomLead DeveloperLead DeveloperNo worries! You can add that code like this: https://docs.generatepress.com/article/adding-php/
July 20, 2017 at 7:54 pm #352540DanThanks Tom! Okay, so I put that in the functions.php file in my child theme and it worked. However it hides the GeneratePress option for everyone including the Admin, which is probably not good. Any way to do this for every user type but the Admin?
July 20, 2017 at 8:01 pm #352545DanBy the way, I do have the GP Premium if it helps to do it another way. Like maybe in the Hooks. But I thought the functions.php would be a better option for this.
July 20, 2017 at 8:26 pm #352550TomLead DeveloperLead Developerfunctions.php is definitely better.
I just adjusted the code above – can you try it instead of the previous function (be sure to remove the one you already added).
July 20, 2017 at 8:36 pm #352553DanHmmm. That actually put the GeneratePress Appearance menu back in for both Admin and Editor users. Looks like you changed the after_setup_theme to wp, correct? I do not know php at all, but could it be something with the current_user_can part of the code? (Just throwing ideas out there, not trying to say I know anything. ๐ )
July 20, 2017 at 8:41 pm #352555TomLead DeveloperLead DeveloperHmm, that means the plugin you’re using is giving the user the same privileges as admins, as that code will only run if the current user has the ability to manage the network, which is as high as you can go when it comes to admin privileges.
We could try to make it so it only shows inside your account?
July 20, 2017 at 8:44 pm #352559DanThat could work. And I could adjust for anyone else that I might make an Admin in the future. Do you know a code for that?
July 20, 2017 at 8:46 pm #352560DanAnd sorry for the back and forth. This plugin, Editor Menu and Widget Access, is the only plugin I have found that gives access to the Menus and Widgets to the Editor user of the site. Could not find another way to do that.
July 21, 2017 at 9:18 am #352815TomLead DeveloperLead DeveloperTry this:
add_action( 'init','tu_remove_gp_admin_menu' ); function tu_remove_gp_admin_menu() { $current_user = wp_get_current_user(); if ( 'admin' !== $current_user->user_login ) { remove_action('admin_menu', 'generate_create_menu'); remove_action( 'admin_menu', 'generate_do_dashboard_menu' ); } }
July 21, 2017 at 9:37 am #352829DanSame thing happened as in the first set of code. The GeneratPress Appearance menu is gone for both Admin and Editor. Would it be easier if I made you a user on the site? Or do you not want that, which I would totally understand.
-
AuthorPosts
- The topic ‘Hide GeneratePress from Dashboard in Editor view…’ is closed to new replies.