juillet 12

Masquer des sous-menus de l’admin

On peut autoriser un utilisateur à avoir accès au menu « apparence » sans pour autant qu’il puisse gérer les widgets et les options du thèmes.

Dans functions.php :

add_action( 'admin_menu', 'remove_admin_menus' );
add_action( 'admin_menu', 'remove_admin_submenus' );

//Remove top level admin menus
function remove_admin_menus() {
    remove_menu_page( 'edit-comments.php' );
    remove_menu_page( 'link-manager.php' );
    remove_menu_page( 'tools.php' );
    remove_menu_page( 'plugins.php' );
    remove_menu_page( 'users.php' );
    remove_menu_page( 'options-general.php' );
    remove_menu_page( 'upload.php' );
    remove_menu_page( 'edit.php' );
    remove_menu_page( 'edit.php?post_type=page' );
    remove_menu_page( 'themes.php' );
}

//Remove sub level admin menus
function remove_admin_submenus() {
    remove_submenu_page( 'themes.php', 'theme-editor.php' );
    remove_submenu_page( 'themes.php', 'themes.php' );
    remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );
    remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
    remove_submenu_page( 'edit.php', 'post-new.php' );
    remove_submenu_page( 'themes.php', 'nav-menus.php' );
    remove_submenu_page( 'themes.php', 'widgets.php' );
    remove_submenu_page( 'themes.php', 'theme-editor.php' );
    remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
    remove_submenu_page( 'plugins.php', 'plugin-install.php' );
    remove_submenu_page( 'users.php', 'users.php' );
    remove_submenu_page( 'users.php', 'user-new.php' );
    remove_submenu_page( 'upload.php', 'media-new.php' );
    remove_submenu_page( 'options-general.php', 'options-writing.php' );
    remove_submenu_page( 'options-general.php', 'options-discussion.php' );
    remove_submenu_page( 'options-general.php', 'options-reading.php' );
    remove_submenu_page( 'options-general.php', 'options-discussion.php' );
    remove_submenu_page( 'options-general.php', 'options-media.php' );
    remove_submenu_page( 'options-general.php', 'options-privacy.php' );
    remove_submenu_page( 'options-general.php', 'options-permalinks.php' );
    remove_submenu_page( 'index.php', 'update-core.php' );
}

Ce hack utilise les slugs des menu admin de WordPress

Dashboard remove_menu_page(‘index.php’);
Dashboard remove_submenu_page( ‘index.php’, ‘index.php’ );
Updates remove_submenu_page( ‘index.php’, ‘update-core.php’ );

Posts remove_menu_page(‘edit.php’);
Posts remove_submenu_page( ‘edit.php’, ‘edit.php’ );
Add New remove_submenu_page( ‘edit.php’, ‘post-new.php’ );
Categories remove_submenu_page( ‘edit.php’, ‘edit-tags.php?taxonomy=category’ );
Post Tags remove_submenu_page( ‘edit.php’, ‘edit-tags.php?taxonomy=post_tag’ );
Media remove_menu_page(‘upload.php’);
Library remove_submenu_page( ‘upload.php’, ‘upload.php’ );
Add New remove_submenu_page( ‘upload.php’, ‘media-new.php’ );
Links remove_menu_page(‘link-manager.php’);
Links remove_submenu_page( ‘link-manager.php’, ‘link-manager.php’ );
Add New remove_submenu_page( ‘link-manager.php’, ‘link-add.php’ );
Link Categories remove_submenu_page( ‘link-manager.php’, ‘edit-tags.php?taxonomy=link_category’ );
Pages remove_menu_page(‘edit.php?post_type=page’);
Pages remove_submenu_page( ‘edit.php?post_type=page’, ‘edit.php?post_type=page’ );
Add New remove_submenu_page( ‘edit.php?post_type=page’, ‘post-new.php?post_type=page’ );
Comments remove_menu_page(‘edit-comments.php’);

Appearance remove_menu_page(‘themes.php’);
Themes remove_submenu_page( ‘themes.php’, ‘themes.php’ );
Widgets remove_submenu_page( ‘themes.php’, ‘widgets.php’ );
Menus remove_submenu_page( ‘themes.php’, ‘nav-menus.php’ );
Editor remove_submenu_page( ‘themes.php’, ‘theme-editor.php’ );
Plugins remove_menu_page(‘plugins.php’);
Plugins remove_submenu_page( ‘plugins.php’, ‘plugins.php’ );
Add New remove_submenu_page( ‘plugins.php’, ‘plugin-install.php’ );
Editor remove_submenu_page( ‘plugins.php’, ‘plugin-editor.php’ );
Users remove_menu_page(‘users.php’);
Users remove_submenu_page( ‘users.php’, ‘users.php’ );
Add New remove_submenu_page( ‘users.php’, ‘user-new.php’ );
Your Profile remove_submenu_page( ‘users.php’, ‘profile.php’ );
Tools remove_menu_page(‘tools.php’);
Tools remove_submenu_page( ‘tools.php’, ‘tools.php’ );
Import remove_submenu_page( ‘tools.php’, ‘import.php’ );
Export remove_submenu_page( ‘tools.php’, ‘export.php’ );
Settings remove_menu_page(‘options-general.php’);
General remove_submenu_page( ‘options-general.php’, ‘options-general.php’ );
Writing remove_submenu_page( ‘options-general.php’, ‘options-writing.php’ );
Reading remove_submenu_page( ‘options-general.php’, ‘options-reading.php’ );
Discussion remove_submenu_page( ‘options-general.php’, ‘options-discussion.php’ );
Media remove_submenu_page( ‘options-general.php’, ‘options-media.php’ );
Privacy remove_submenu_page( ‘options-general.php’, ‘options-privacy.php’ );
Permalinks remove_submenu_page( ‘options-general.php’, ‘options-permalink.php’ );
lien –

Étiquettes :
Copyright 2019. All rights reserved.

Ecrit 12 juillet 2012 par Pit dans la catégorie "WORDPRESS