'wordpressLogin' => false,
'wpUser' => false,
'contactsEmail' => false,
- 'contactsUsername' => false
+ 'contactsUsername' => false,
+ 'active' => false
);
// If E-mail address is not supplied
$contact = $this->wpdb->get_row("SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "contacts WHERE email = '$email';", ARRAY_A);
if ($contact !== null) {
$r['contactsEmail'] = true;
+ $r['active'] = ($r['active'] > 0);
}
$contact = $this->wpdb->get_row("SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "contacts WHERE username = '$username';", ARRAY_A);
if ($contact !== null) {
$r['contactsUsername'] = true;
+ $r['active'] = ($r['active'] > 0);
}
return $r;
* version nunmber of that release for the DB version.
*/
define('GLM_MEMBERS_CONTACTS_PLUGIN_VERSION', '1.0.3');
+define('GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.44');
define('REQUIRED_GLM_MEMBERS_PLUGIN_MIN_DB_VERSION', '1.0.41');
/*
}
// Function to generate message regarding main GLM Member DB plugin version is not receint enought to run this add-on
-function glmMembersBlankPluginMinVerRequired() {
+function glmMembersContactsMembersMinVerRequired() {
+ $curVer = get_option('glmMembersDatabasePluginVersion');
echo '
<div class="error">
<p>The '.GLM_MEMBERS_CONTACTS_PLUGIN_NAME.' requires that the main GLM Member DB plugin version be no older than '
- .GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION.'!</p>
+ .GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION.' but the current verssion is '.$curVer.'!</p>
<p>The '.GLM_MEMBERS_CONTACTS_PLUGIN_NAME.' plugin has been de-activated.</p>
</div>
';
*/
$glmMembersDatabasePluginVersion = get_option('glmMembersDatabasePluginVersion');
if (version_compare($glmMembersDatabasePluginVersion, GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION) < 0) {
- add_action( 'admin_notices', 'glmMembersPluginMinVerRequired');
+ add_action( 'admin_notices', 'glmMembersContactsMembersMinVerRequired');
deactivate_plugins('/'.GLM_MEMBERS_CONTACTS_PLUGIN_SLUG.'/'.GLM_MEMBERS_CONTACTS_PLUGIN_SLUG.'.php');
}
*/
require_once(GLM_MEMBERS_CONTACTS_PLUGIN_SETUP_PATH.'/permissions.php');
-
-// If they are a restricted user, kick them back out
+/*
+ * Notification to user if logging in with restricted contact
+ */
+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;\">
+ <b>NOTE:</b> You are trying to log into a contact account that is for informational purposes only
+ or has been temporarily dissabled. You are not permitted to log in with that contact account at this time.
+ </div>
+ ";
+ return $message;
+}
+$restrictedLoginAttempt = get_option('glmMembersDatabaseContactsRestrictedLogin');
+if ($restrictedLoginAttempt) {
+ add_filter('login_message', 'glmMembersContactsNoLoginMessage');
+ delete_option('glmMembersDatabaseContactsRestrictedLogin');
+}
if (current_user_can('glm_members_restricted_contact')) {
+ update_option('glmMembersDatabaseContactsRestrictedLogin', true);
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) {
+ update_option('glmMembersDatabaseContactsRestrictedLogin', true);
+ wp_logout();
+}
+
+
+
+
/*
* Add filter to redirect user to a particular destination on
* login based on their roles.
foreach ($user->roles as $r) {
if (substr($r,0,12) != 'glm_members_') {
// Go to normal destination for this user
- return $redirect_to();
+ return $redirect_to;
}
}
$newContactCreated = true;
- // Store the contact ID, user entityType, and entityID into user meta data
+ // Store the contact ID and active status into user meta data
update_user_meta($userID, 'glmMembersContactID', $this->contactInfo['fieldData']['id']);
+ update_user_meta($userID, 'glmMembersContactActive', $this->contactInfo['fieldData']['active']['value']);
break;
}
$this->contactInfo = $this->editEntry(($_REQUEST['id']-0));
$contactUpdated = true;
+ // Get the wordpress user ID
+ $wpUser = get_user_by('email', $this->contactInfo['fieldData']['email']);
+
// Check for password changes and update Wordpress user
if (trim($_REQUEST['password']) != '') {
- // Get the wordpress user ID
- $wpUser = get_user_by('email', $this->contactInfo['fieldData']['email']);
-
// If we got a good user, set the new password
if ($wpUser) {
wp_set_password($_REQUEST['password'], $wpUser->ID);
$wpUser->add_role($wpRole);
}
+ // Update contact active status in user meta data
+ update_user_meta($wpUser->ID, 'glmMembersContactActive', $this->contactInfo['fieldData']['active']['value']);
+
}
$option = 'edit';
wp_delete_user($wpUser->ID);
$wpUserDeleted = true;
+ // Otherwise we need to drop the user meta data we added to the WP user.
+ } else {
+ delete_user_meta($userID->ID, 'glmMembersContactID');
+ delete_user_meta($userID->ID, 'glmMembersContactActive');
}
// Return to list by falling through here.