From 1d8ddc12d50ad3860f94cf7217ac5c6ee2b364b4 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 9 Sep 2016 15:02:25 -0400 Subject: [PATCH] Added code to block everyone except Administrators from the main WordPress admin Dashboard. Redirects them to the main GLM Associate menu when they do get to the main admin Dashboard. --- setup/adminHooks.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 2200cb24..0076fe75 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -123,4 +123,32 @@ add_action( 'add_meta_boxes', function() { //} +// If not administrator, don't show or permit access to the main dashboard +function glmRemoveDashboard () { + global $current_user, $menu, $submenu; + + // If user isn't an administrator + if (!in_array('administrator', $current_user->roles)) { + + // Get rid of the main WordPress admin "Dashboard" + reset( $menu ); + $page = key( $menu ); + while( ( __( 'Dashboard' ) != $menu[$page][0] ) && next( $menu ) ) { + $page = key( $menu ); + } + if( __( 'Dashboard' ) == $menu[$page][0] ) { + unset( $menu[$page] ); + } + reset($menu); + + // Also redirect user away from main WordPress dashboard should they get there. + if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI'] ) && ( 'index.php' != $menu[$page][2] ) ) { + wp_redirect( get_option( 'siteurl' ) . '/wp-admin/admin.php?page=glm-members-admin-menu-member'); + } + + } +} +add_action('admin_menu', 'glmRemoveDashboard'); + + ?> -- 2.17.1