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.

Hide GeneratePress and Customizer from Role

  • I have a custom role “lap_manager” based on “editor” that I have enabled the capability “edit_theme_options” to allow access to edit the menus. However this then also enables Themes, Widgets, Customizer and GeneratePress.

    I have been able remove Widgets and Themes with the following, can could hide the Customizer with CSS, but can’t work out how to remove GeneratePress.

    // Hide Menus from lap_manager role
    function hide_menu() {
    
      if ( current_user_can( 'lap_manager' ) ) {
        // Hide theme selection page
        remove_submenu_page( 'themes.php', 'themes.php' );
    
        // Hide widgets page
        remove_submenu_page( 'themes.php', 'widgets.php' );
    
        // Hide customize page (alternative method)
        global $submenu;
        unset($submenu['themes.php'][6]);
      }
    }
    
    add_action('admin_menu', 'hide_menu'); // Changed hook to 'admin_menu'
  • Try this:

    function hide_menu() {
        if ( current_user_can( 'lap_manager' ) ) {
    	//hide themes
    	remove_submenu_page( 'themes.php', 'themes.php' );
    
            //hide widgets
            remove_submenu_page( 'themes.php', 'widgets.php' );
    
    	//hide generatepress
    	remove_submenu_page( 'themes.php', 'generate-options' );
    		
            //hide Customizer, assuming customizer is the 6th menu 
           global $submenu;
           foreach ( $submenu['themes.php'] as $key => $item ) {
               if ( isset( $item[6] ) ) {
                   unset( $submenu['themes.php'][$key] );
                   break; 
               }		 
           }		 
        }
    }
    
    add_action( 'admin_menu', 'hide_menu', 999 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.