- <?php
 - function remove_menus(){
 - /*
 - * Available defaults
 - */
 - /*
 - remove_menu_page( 'index.php' ); //Dashboard
 - remove_menu_page( 'jetpack' ); //Jetpack*
 - remove_menu_page( 'edit.php' ); //Posts
 - remove_menu_page( 'upload.php' ); //Media
 - remove_menu_page( 'edit.php?post_type=page' ); //Pages
 - remove_menu_page( 'edit-comments.php' ); //Comments
 - remove_menu_page( 'themes.php' ); //Appearance
 - remove_menu_page( 'plugins.php' ); //Plugins
 - remove_menu_page( 'users.php' ); //Users
 - remove_menu_page( 'profile.php' ); //Profile
 - remove_menu_page( 'tools.php' ); //Tools
 - remove_menu_page( 'options-general.php' ); //Settings
 - */
 - /*
 - * Current user can -> https://codex.wordpress.org/Function_Reference/current_user_can
 - * Roles and capabilities -> https://codex.wordpress.org/Roles_and_Capabilities
 - */
 - /*
 - * Role -> Is not Administrator
 - */
 - if (!(current_user_can('administrator'))) {
 - remove_menu_page( 'plugins.php' ); //Plugins
 - remove_menu_page( 'profile.php' ); //Profile
 - /*
 - * Role -> KHD Management
 - */
 - if ( current_user_can('khd_management') ) {
 - remove_menu_page( 'options-general.php' ); //Settings
 - remove_menu_page( 'themes.php' ); //Appearance
 - remove_menu_page( 'wpcf7' ); //Contact forms
 - remove_menu_page( 'tools.php' ); //Tools
 - remove_menu_page( 'edit.php' ); //Posts
 - remove_menu_page( 'edit.php?post_type=page' ); //Pages
 - remove_menu_page( 'edit-comments.php' ); //Comments
 - }
 - /*
 - * Role -> KHD Admin
 - */
 - if ( current_user_can('khd_admin') ) {
 - remove_menu_page( 'tools.php' ); //Tools
 - }
 - /*
 - * Role -> default users without a special role from LDAP
 - */
 - if ( current_user_can('subscriber') ) {
 - wp_safe_redirect( home_url() );
 - }
 - }
 - }
 - add_action( 'admin_menu', 'remove_menus' );
 - /*
 - * Hard remove Menu items if the hook `admin_menu` is not working at some menus
 - */
 - function remove_menus_admin_init() {
 - /*
 - * Role -> KHD Management
 - */
 - if ((current_user_can('khd_management'))) {
 - remove_menu_page( 'activity_log_page' );
 - remove_menu_page( 'khd-general-settings' );
 - //wp_redirect( admin_url( 'edit.php?post_type=message' ) );
 - }
 - /*
 - * Role -> KHD Admin
 - */
 - if ((current_user_can('khd_admin'))) {
 - remove_menu_page( 'mo_ldap_local_login' ); //LDAP
 - remove_menu_page( 'edit.php?post_type=acf-field-group' ); //ACF
 - remove_menu_page( 'edit-comments.php?page=wpdiscuz_options_page' );
 - }
 - };
 - add_action('admin_init', 'remove_menus_admin_init');
 - /*
 - * DEBUG - IF MENUS WILL NOT HIDE - locate the plugin-slug [02] and use it instead menu-slug in `admin_init`
 - */
 - /*
 - function the_dramatist_debug_admin_menu() {
 - echo '<pre>' . print_r( $GLOBALS[ 'menu' ], TRUE) . '</pre>';
 - }
 - add_action( 'admin_init', 'the_dramatist_debug_admin_menu' );
 - */
 - function remove_dashboard_widgets() {
 - global $wp_meta_boxes;
 - //print_r($wp_meta_boxes);
 - /*
 - * Role -> KHD Management
 - */
 - if ((current_user_can('khd_management'))) {
 - //unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
 - //unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); // WP Infos (Posts, Pages, ...)
 - }
 - /*
 - * Role -> KHD Admin
 - */
 - if ((current_user_can('khd_admin'))) {
 - }
 - }
 - add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
 - /*
 - * Admin Top bar
 - */
 - function remove_wp_nodes() {
 - global $wp_admin_bar;
 - $wp_admin_bar->remove_node( 'wp-logo' );
 - $wp_admin_bar->remove_node( 'new-content' ); //New page, post, media, link, etc.
 - $wp_admin_bar->remove_node( 'archive' ); //View Post type archive link
 - $wp_admin_bar->remove_node( 'my-account' ); //Top Right Account info
 - }
 - add_action( 'admin_bar_menu', 'remove_wp_nodes', 999 );
 - /*
 - * Rename Posts to News Articles
 - */
 - function change_post_menu_label() {
 - global $menu;
 - global $submenu;
 - $menu[5][0] = 'News Articles';
 - $submenu['edit.php'][5][0] = __('News Articles', LOCAL);
 - $submenu['edit.php'][10][0] = __('Add News Article', LOCAL);
 - $submenu['edit.php'][16][0] = __('Tags', LOCAL);
 - echo '';
 - }
 - add_action( 'admin_menu', 'change_post_menu_label' );
 - function change_post_object_label() {
 - global $wp_post_types;
 - $labels = &$wp_post_types['post']->labels;
 - $labels->name = __('News Articles', LOCAL);
 - $labels->singular_name = __('News Article', LOCAL);
 - $labels->add_new = __('Add News Article', LOCAL);
 - $labels->add_new_item = __('Add News Article', LOCAL);
 - $labels->edit_item = __('Edit News Article', LOCAL);
 - $labels->new_item = __('News Article', LOCAL);
 - $labels->view_item = __('View News Article', LOCAL);
 - $labels->search_items = __('Search News Articles', LOCAL);
 - $labels->not_found = __('No News Articles found', LOCAL);
 - $labels->not_found_in_trash = __('No News Articles found in Trash', LOCAL);
 - }
 - add_action( 'init', 'change_post_object_label' );
 - /*
 - * Update Notes
 - */
 - function hide_update_notice_to_all_but_admin_users()
 - {
 - if (!current_user_can('update_core')) {
 - remove_action( 'admin_notices', 'update_nag', 3 );
 - }
 - }
 - add_action( 'admin_head', 'hide_update_notice_to_all_but_admin_users', 1 );
 
Recent Pastes