From: Chuck Scott Date: Tue, 31 Jan 2017 17:48:51 +0000 (-0500) Subject: Fixed issues with visibility of main dashboard based on user role/capabilities X-Git-Tag: v2.9.5^2~4 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=26980cd8c60432df35e8f2bd30e7c3642bf54531;p=WP-Plugins%2Fglm-member-db.git Fixed issues with visibility of main dashboard based on user role/capabilities --- diff --git a/setup/adminHooks.php b/setup/adminHooks.php index da9b6860..1e17be26 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -103,32 +103,44 @@ 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, $config; + global $menu; - // If user isn't an administrator - if (!in_array('administrator', $current_user->roles) && $config['settings']['enable_members']) { + // Specify the menu item(s) to be removed + $restricted = array(__('Dashboard')); - // 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); + // Point the menu array pointer to the end + end($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'); - } + // Working our way back up the menu + while(prev($menu)){ + + // Break out the data for the current menu item + $value = explode(' ',$menu[key($menu)][0]); + // If there is a name for this menu and it's in the restircted list + if(in_array($value[0]!= NULL?$value[0]:'',$restricted)) { + + // Remove this menu item + unset($menu[key($menu)]); + + } } + + return; + +} +// If user isn't an administrator - Remove the main dashboard +global $current_user; +if (!in_array('administrator', $current_user->roles)) { + add_action('admin_menu', 'glmRemoveDashboard'); } -add_action('admin_menu', 'glmRemoveDashboard'); + +// If members are enabled if ( isset( $config ) && isset( $config['settings'] ) && $config['settings']['enable_members'] ) { + + // Add member widgets + add_filter( 'glm-member-db-dashboard-member-widgets', function ( $member = null ) {