Archived topic
Hide GeneratePress' customizer option by role
10 replies · Started by gregoirenoyelle on July 2, 2020
Hi !
Is-there a way to hide some GeneratePress's customizer options for a specific role?
I know how to use the current_user_can condition. I don't want to use a plugin for that.
I find this link: Remove all GP Customizer options. Is there the all list here?
Thanks :)
That function is likely your best bet, although it is subject to change (if we re-organize etc..), so keep an eye on it.
Let me know if you run into any issues :)
Hi Tom,
OK thanks. I will test and I will add an example for the others.
Thanks!
@gregoirenoyelle, ever got your code to work? I'm currently searching for the same thing.
Show and hide customizer Panels, sections and settings based on user role.
Thanks
I just figured out, Thanks.
Ok @Ismael . Great
I ran into this ticket as I was trying to give my editor user the ability to add menus, without having access to the full "Appearance". I found the below code, and have managed to hide everything I need to hide except for the Generate Options Page.
/* Give Editor Appearance Edit Privilege */
function add_theme_caps() {
$role_object = get_role( 'editor' );
$role_object->add_cap( 'edit_theme_options' );
}
add_action( 'admin_init', 'add_theme_caps');
/* Hide Appearance Submenus Except Menu Page */
function hide_menu() {
if (current_user_can('editor')) {
remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
remove_submenu_page( 'themes.php', 'themes.php?page=generate-options' ); // hide theme options
remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu
remove_submenu_page( 'themes.php', 'customize.php' ); // hide the customizer submenu
remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2F' ); // hide the customizer submenu
}
}
add_action('admin_head', 'hide_menu');
This line below isn't doing the trick and I would like to know if there is a way to resolve that.
remove_submenu_page( 'themes.php', 'themes.php?page=generate-options' ); // hide theme options
Thanks!
Hi Omar,
For one, I think the best way to deal with it is with this filter:
https://docs.generatepress.com/article/generate_dashboard_page_capability/
That very was helpful, Thanks!
No problem. :)