// $result = '<pre>$option2: ' . print_r( $option2, true ) . '</pre>';
switch ( $option2 ) {
+ case 'nomember':
+ $sql = "
+ SELECT id,email
+ FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+ WHERE ref_dest NOT IN (
+ SELECT distinct id FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ )";
+ $member_contacts = $this->wpdb->get_results( $sql, ARRAY_A );
+ foreach ( $member_contacts as $member_contact ) {
+ if ( $member_contact['email'] ) {
+ $wpUser = get_user_by( 'email', $member_contact['email'] );
+ if ( $wpUser ) {
+ // $result .= '<pre>$wpUser: ' . print_r( $wpUser, true ) . '</pre>';
+ // Check for other roles assigned to this user and remove our roles
+ $userHasOtherRole = false;
+ foreach ($wpUser->roles as $r) {
+ if (!in_array($r, $this->config['contact_role_wordpress'])) {
+ // Apparently not, so we need to keep the Wordpress user
+ $userHasOtherRole = true;
+
+ //Otherwise, this is one of our roles so we should remove it just in case the Wordpress user isn't deleted
+ } else {
+ // Remove this role from our user
+ $wpUser->remove_role($r);
+ }
+ }
+ // If the user doesn't have a role other than our members contact roles
+ if (!$userHasOtherRole) {
+
+ // Delete the wordpress user
+ 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($wpUser->ID, 'glmMembersContactID');
+ delete_user_meta($wpUser->ID, 'glmMembersContactActive');
+ }
+ }
+
+ }
+ if ( $member_contact['id'] ) {
+ // Delete the Member Contact
+ $this->wpdb->delete(
+ GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
+ array( 'id' => $member_contact['id'] ),
+ array( '%d' )
+ );
+ }
+ }
+ break;
+
case 'usernames':
$wp_count = 0;
$contact_count = 0;
delete_user_meta($wpUser->ID, 'glmMembersContactActive');
}
}
+
+ }
+ if ( $member_contact['id'] ) {
+ // Delete the Member Contact
+ $this->wpdb->delete(
+ GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
+ array( 'id' => $member_contact['id'] ),
+ array( '%d' )
+ );
}
// Delete member_info records belonging to the archived members.