Fixed up user logout detection and messaging.
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 26 Jan 2016 21:09:13 +0000 (16:09 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 26 Jan 2016 21:09:13 +0000 (16:09 -0500)
glm-member-db-contacts.php
setup/rolesAndCapabilities.php

index e44672d..c15097b 100644 (file)
  *  made together with the DB_VERSION below. ONLY bump the DB
  *  version when there's a change in the database!! Use the
  *  version nunmber of that release for the DB version.
- *
- *  We check the plugin version stored in the WordPress option below
- *  so that we're sure the other add-ons see an up to date
- *  version from this plugin.
  */
 define('GLM_MEMBERS_CONTACTS_PLUGIN_VERSION', '1.0.7');
 define('GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.44');
 define('REQUIRED_GLM_MEMBERS_PLUGIN_MIN_DB_VERSION', '1.0.41');
 
-// Check if plugin version is not current in WordPress option and if needed updated it
-if (GLM_MEMBERS_CONTACTS_PLUGIN_VERSION != get_option('glmMembersDatabaseContactsPluginVersion')) {
-    update_option('glmMembersDatabaseContactsPluginVersion', GLM_MEMBERS_CONTACTS_PLUGIN_VERSION);
-}
-
 /*
  * Copyright 2014 Charles Scott (email : cscott@gaslightmedia.com)
  *
@@ -182,43 +173,49 @@ add_filter('glm-member-db-register-addon','glmMembersRegisterContacts', 10, 1);
 require_once(GLM_MEMBERS_CONTACTS_PLUGIN_SETUP_PATH.'/permissions.php');
 
 /*
- * Notification to user if logging in with restricted or inactive contact
+ * Login Checks and Messages
  */
+
+$wpUserID = get_current_user_id();
+
+// Message to display on Login page after a forced logout detection
 function glmMembersContactsNoLoginMessage( $message ) {
         $message .= "
             <div style=\"border-left:4px solid #dd3d36;background:#fff;box-shadow:0 1px 1px 0 rgba(0,0,0,.1);padding-left: .5em;\">
                 <p><b>NOTE:</b> You are trying to log into a contact account that is for informational purposes only
-                or has been temporarily dissabled.</p>
-                <p style=\"margin-top: 1em;\">You are not permitted to log in with that contact account at this time.</p>
+                    or has been temporarily dissabled.</p>
+                <p>You are not permitted to log in with that contact account at this time.</p>
             </div>
         ";
         return $message;
 }
-/*
+
 // If login is from user who was logged out due to restriction or being flagged inactive - Display login message
 if (isset($_COOKIE['glmMembersForcedLogout'])) {
     add_filter('login_message', 'glmMembersContactsNoLoginMessage');
     setcookie ("glmMembersForcedLogout", "", time() - 3600);
 }
-// Check for a restricted contact user and log them out with login message
-if (current_user_can('glm_members_restricted_contact')) {
-    setcookie ("glmMembersForcedLogout", "stuff", time() + 3600, '/');
+
+// Check if user's only role is as a restricted contact
+$userRoles = get_userdata($wpUserID)->roles;
+if (in_array('glm_members_restricted_contact', $userRoles) && count($userRoles) == 1) {
+    setcookie ("glmMembersForcedLogout", "Forced Logout", time() + 3600, '/');
     wp_logout();
 }
+
 // Check for a contact user that's inactive and send them back to login also
-$wpUserID = get_current_user_id();
 $contactUser = get_user_meta($wpUserID, 'glmMembersContactID', true);
 $contactActive = get_user_meta($wpUserID, 'glmMembersContactActive', true);
 if ($contactUser && !$contactActive) {
-    setcookie ("glmMembersForcedLogout", "stuff", time() + 3600, '/');
+    setcookie ("glmMembersForcedLogout", "Forced Logout", time() + 3600, '/');
     wp_logout();
 }
-*/
 
 /*
  * Add filter to redirect user to a particular destination on
  * login based on their roles.
  */
+
 function my_login_redirect( $redirect_to, $request, $user ) {
 
     global $user;
index 045ea30..25c6c62 100644 (file)
  */
 
 // *** TEMPORARY TO REMOVE OLD ROLSES
+/*
 remove_role('glm_own_member_manager');
 remove_role('glm_own_entity_manager');
 remove_role('glm_member_contact');
 remove_role('glm_member_restricted_contact');
 remove_role('glm_members_own_member_manager');
+*/
 
 /*
 // Un-comment to fully reset all contact roles