[Support request] Hide GeneratePress from Dashboard in Editor view…

Home Forums Support [Support request] Hide GeneratePress from Dashboard in Editor view…

Home Forums Support Hide GeneratePress from Dashboard in Editor view…

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #322461
    Dan

    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?

    #322615
    Tom
    Lead Developer
    Lead Developer

    By 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 ๐Ÿ™‚

    #322669
    Dan

    Hey 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.

    #322887
    Tom
    Lead Developer
    Lead Developer

    Hmm, 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' );
        }
    }
    #352416
    Dan

    Hi 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.

    #352534
    Tom
    Lead Developer
    Lead Developer

    No worries! You can add that code like this: https://docs.generatepress.com/article/adding-php/

    #352540
    Dan

    Thanks 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?

    #352545
    Dan

    By 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.

    #352550
    Tom
    Lead Developer
    Lead Developer

    functions.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).

    #352553
    Dan

    Hmmm. 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. ๐Ÿ™‚ )

    #352555
    Tom
    Lead Developer
    Lead Developer

    Hmm, 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?

    #352559
    Dan

    That 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?

    #352560
    Dan

    And 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.

    #352815
    Tom
    Lead Developer
    Lead Developer

    Try 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' );
        }
    }
    #352829
    Dan

    Same 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.

Viewing 15 posts - 1 through 15 (of 21 total)
  • The topic ‘Hide GeneratePress from Dashboard in Editor view…’ is closed to new replies.