}
$r = array(
- 'wpUserEmail' => false,
- 'wordpressEmail' => false,
- 'wpUserLogin' => false,
- 'wordpressLogin' => false,
- 'wpUser' => false,
- 'contactsEmail' => false,
+ 'wpUserEmail' => false,
+ 'wordpressEmail' => false,
+ 'wpUserLogin' => false,
+ 'wordpressLogin' => false,
+ 'wpUser' => false,
+ 'contactsEmail' => false,
'contactsUsername' => false,
- 'active' => false
+ 'active' => false
);
// Check Wordpress
- $r['wpUserEmail'] = get_user_by( 'email', $email );
- If ($r['wpUserEmail']) {
- $r['wordpressEmail'] = true;
- }
- $r['wpUserLogin'] = get_user_by( 'login', $username );
- If ($r['wpUserLogin']) {
- $r['wordpressLogin'] = true;
+ if ( $email ) {
+ $r['wpUserEmail'] = get_user_by( 'email', $email );
+ If ($r['wpUserEmail']) {
+ $r['wordpressEmail'] = true;
+ }
+ } else {
+ $wpUser = get_user_by( 'login', $username );
+ $r['wpUserLogin'] = $wpUser;
+ $r['wpUserEmail'] = $wpUser;
+ If ($r['wpUserLogin']) {
+ $r['wordpressLogin'] = true;
+ }
}
// Check Contacts
// Get the wordpress user ID
$wpUser = get_user_by('email', $contactInfo['fieldData']['email']);
+ // If we cannot find user by email try the login using username
+ if ( !$wpUser ) {
+ $wpUser = get_user_by('login', $contactInfo['fieldData']['username']);
+ }
+ // echo '<pre>$wpUser: ' . print_r( $wpUser, true ) . '</pre>';
+
// Check for password changes and update Wordpress user
if (trim($_REQUEST['password']) != '') {
// If there's a role change, update the user role for WordPress
if ($wpRole != $savedContactRole['wpRole']) {
$contactCheck = $this->checkContact($contactInfo['fieldData']['email']);
- $wpUser = new WP_User($contactCheck['wpUserEmail']->ID);
+ // Updating this to deal with imported members that did not have an email.
+ if ( isset( $contactCheck['wpUserEmail'] ) ) {
+ $wpUser = new WP_User($contactCheck['wpUserEmail']->ID);
+ } else if ( isset( $contactCheck['wpUserLogin'] ) ) {
+ $wpUser = new WP_User($contactCheck['wpUserLogin']->ID);
+ }
$wpUser->remove_role($savedContactRole['wpRole']);
$wpUser->add_role($wpRole);
}
// Only list member contacts for the selected member
if ($haveMember) {
+ $other_members_refs = false;
// Have to query the meta data before sending it back into
// db query. Would work but it's getting back a string
// instead of an array of ints.
- $other_members_refs = $this->wpdb->get_var(
- "SELECT meta_value
- FROM " . $this->wpdb->prefix . "usermeta
- WHERE meta_key = 'glmMembersContactMembers'
- AND meta_value LIKE '%" . $this->memberID . "%'"
+ // Should only be getting the meta data for the real contact.
+ // Get userID for original member contact.
+ $originalMemberContact = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT id,email,username
+ FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+ WHERE ref_dest = %d",
+ $this->memberID
+ ),
+ ARRAY_A
);
+ if ( isset( $originalMemberContact ) ) {
+ $wpUser = $this->checkContact( $originalMemberContact['email'], $originalMemberContact['username'] );
+ // echo '<pre>$wpUser: ' . print_r( $wpUser, true ) . '</pre>';
+ $other_members_refs = $this->wpdb->get_var(
+ "SELECT meta_value
+ FROM " . $this->wpdb->prefix . "usermeta
+ WHERE meta_key = 'glmMembersContactMembers'
+ AND meta_value LIKE '%" . $this->memberID . "%'
+ AND user_id = " . $wpUser['wpUserEmail']->ID
+ );
+ // echo '<pre>$other_members_refs: ' . print_r( $other_members_refs, true ) . '</pre>';
+ // Get wordpress user
+ } else {
+ $other_members_refs = $this->wpdb->get_var(
+ "SELECT meta_value
+ FROM " . $this->wpdb->prefix . "usermeta
+ WHERE meta_key = 'glmMembersContactMembers'
+ AND meta_value LIKE '%" . $this->memberID . "%'"
+ );
+ }
$where .= " AND ref_type = " . $this->config['ref_type_numb']['Member'];
if ( $other_members_refs ) {
// Make sure the $other_members_refs is correct
// Attempt to get WordPress user data
$wpUserID = false;
- $contactCheck = $this->checkContact($contactInfo['fieldData']['email']);
+ $contactCheck = $this->checkContact( $contactInfo['fieldData']['email'], $contactInfo['fieldData']['username'] );
if ($contactCheck['wpUserEmail']) {
$wpUser = new WP_User($contactCheck['wpUserEmail']->ID);
$wpUserID = $wpUser->ID;
+ } else if ( $contactCheck['wpUserLogin'] ) {
+ $wpUser = new WP_User($contactCheck['wpUserLogin']->ID);
+ $wpUserID = $wpUser->ID;
}
$contactMembersList = '';