From: Chuck Scott Date: Tue, 31 Jan 2017 20:39:49 +0000 (-0500) Subject: Fixed problem when a user is sent to an admin member page with members turned off... X-Git-Tag: v2.9.5^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=1a4dd8edc3633d45c2a740a3c4f61cfd90faea4e;p=WP-Plugins%2Fglm-member-db.git Fixed problem when a user is sent to an admin member page with members turned off in the main plugin. Now just sends any user headed to the "Member" menu to the "Members" menu, which is the GLM Associate default. --- diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 1e17be26..9b8df255 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -101,40 +101,53 @@ add_action( 'add_meta_boxes', function() { ); } ); -// If not administrator, don't show or permit access to the main dashboard -function glmRemoveDashboard () { - global $menu; +// Some menu related checks +function glmAdminMenuTests () { + global $menu, $current_user, $config; - // Specify the menu item(s) to be removed - $restricted = array(__('Dashboard')); + // If not administrator, don't show or permit access to the main dashboard + if (!in_array('administrator', $current_user->roles)) { - // Point the menu array pointer to the end - end($menu); + // Specify the menu item(s) to be removed + $restricted = array(__('Dashboard')); - // Working our way back up the menu - while(prev($menu)){ + // Point the menu array pointer to the end + end($menu); - // Break out the data for the current menu item - $value = explode(' ',$menu[key($menu)][0]); + // Working our way back up the menu + while(prev($menu)){ - // If there is a name for this menu and it's in the restircted list - if(in_array($value[0]!= NULL?$value[0]:'',$restricted)) { + // Break out the data for the current menu item + $value = explode(' ',$menu[key($menu)][0]); - // Remove this menu item - unset($menu[key($menu)]); + // 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)]); + + } + } + } + + // Also check if members are turned off + if (!$config['settings']['enable_members']) { + + // Check if this is a request to the member menu + if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'glm-members-admin-menu-member') { + + // Do an immediate redirect to the members menu page + $sendToUrl = get_admin_url() . "admin.php?page=glm-members-admin-menu-members"; + wp_redirect($sendToUrl); + exit; } + } 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', 'glmAdminMenuTests'); // If members are enabled if ( isset( $config ) && isset( $config['settings'] ) && $config['settings']['enable_members'] ) {