Fixed problem when a user is sent to an admin member page with members turned off...
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 31 Jan 2017 20:39:49 +0000 (15:39 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 31 Jan 2017 20:39:49 +0000 (15:39 -0500)
Now just sends any user headed to the "Member" menu to the "Members" menu, which is the GLM Associate default.

setup/adminHooks.php

index 1e17be2..9b8df25 100644 (file)
@@ -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'] ) {