Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
This code should be include in functions.php
*/
/* Custom 'super-editor' user role (ID, not label) */
// This is the name of custom user role, you can change to anything, but this role should be exists
// You can add any custom user role eg. with Vladimir Garagulya User Role Editor plugin
if (current_user_can( 'super-editor' )) {
// Hide unwanted admin menu items with CSS
add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
li#toplevel_page_itsec, li#li#toplevel_page_itsec ul {display:none;}
li#menu-appearance ul li.wp-first-item {display:none;}
li#menu-appearance ul li:nth-child(1), li#menu-appearance ul li:nth-child(2) {display:none;}
li#menu-appearance ul li:nth-child(3), li#menu-appearance ul li:nth-child(4) {display:none;}
li#menu-appearance ul li:nth-child(6) {display:none;}
div.error {display:none;}
#dashboard-widgets {display:none;}
#wp-admin-bar-new-content {display:none;}
</style>';
}
add_action( 'admin_init', 'stop_access_profile' );
add_action( 'admin_enqueue_scripts', 'load_defaults_prevents' );
}
// Restrict roles by hooks
function load_defaults_prevents($hook) {
//var_dump($hook); // Debug the hook in WP backend
if ($hook=="options-general.php" || $hook=="options-writing.php" || $hook=="options-reading.php" || $hook=="options-discussion.php" || $hook=="options-media.php" || $hook=="options-permalink.php" || $hook=="toplevel_page_itsec" || $hook=="security_page_itsec-logs" || $hook=="edit-comments.php" || $hook=="tools.php" || $hook=="widgets.php" || $hook=="customize.php" || $_GET['page']=="your-custom-acf-option-name" || ($hook=="post-new.php" && $_GET['post_type']=="page") ) {
wp_die( 'You are not permitted to view this page.' );
}
}
// Remove the admin menu items
function stop_access_profile() {
// Remove Wordpress notices
remove_action( 'admin_notices', 'maintenance_nag', 10 );
remove_action( 'admin_notices', 'update_nag', 3 );
//remove_menu_page( 'edit.php' ); // Please be take care of this settings, because it may occurs some elementary access problems to logged-in user
remove_menu_page( 'tools.php' );
remove_menu_page( 'widgets.php' );
remove_menu_page( 'customize.php' ); // Appearance / Edit
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'options-general.php' );
remove_menu_page( 'options-writing.php' );
remove_menu_page( 'options-reading.php' );
remove_menu_page( 'options-discussion.php' );
remove_menu_page( 'options-media.php' );
remove_menu_page( 'options-permalink.php' );
remove_submenu_page( 'options-general.php', 'duplicatepost' ); // Duplicate post settings
//admin pages
remove_menu_page( 'admin.php?page=your-custom-acf-option-name' ); // ACF option panel
remove_menu_page( 'edit.php?post_type=acf' ); // ACF menu item
remove_menu_page( 'edit.php?post_type=testimonial' ); // Testimonial custom post type list
remove_menu_page( 'edit.php?post_type=portfolio' ); // Portfolio custom post type list
remove_menu_page( 'edit.php?post_type=page' ); // Pages
remove_menu_page( 'wpcf7' ); // Contact form 7
remove_menu_page( 'edit.php?post_type=vc_grid_item' ); // Visual Composer
remove_menu_page( 'vc-welcome' );
remove_menu_page( 'yp-welcome-screen' );
// iThemes WP Security plugin items
remove_submenu_page( 'admin.php', 'itsec' );
remove_submenu_page( 'admin.php', 'toplevel_page_itsec' );
remove_submenu_page( 'admin.php', 'itsec-logs' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.