f5073b5a by Marty Penner

Cleaned up search and merge functionality

1 parent fa978a0c
...@@ -985,7 +985,7 @@ class Actions { ...@@ -985,7 +985,7 @@ class Actions {
985 $query = " 985 $query = "
986 SELECT ID, user_email 986 SELECT ID, user_email
987 FROM $wpdb->users 987 FROM $wpdb->users
988 WHERE 988 WHERE (
989 (user_login LIKE '%$username%') 989 (user_login LIKE '%$username%')
990 OR (user_email LIKE '%$username%') 990 OR (user_email LIKE '%$username%')
991 OR (ID IN ( 991 OR (ID IN (
...@@ -993,7 +993,7 @@ class Actions { ...@@ -993,7 +993,7 @@ class Actions {
993 FROM $wpdb->usermeta 993 FROM $wpdb->usermeta
994 WHERE (meta_key = 'first_name' OR meta_key = 'last_name') 994 WHERE (meta_key = 'first_name' OR meta_key = 'last_name')
995 AND meta_value LIKE '%$username%' 995 AND meta_value LIKE '%$username%'
996 )) 996 )))
997 AND (ID NOT IN ( 997 AND (ID NOT IN (
998 SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'status' AND meta_value = 'terminated' 998 SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'status' AND meta_value = 'terminated'
999 )) 999 ))
...@@ -1046,24 +1046,26 @@ HTML; ...@@ -1046,24 +1046,26 @@ HTML;
1046 ))); 1046 )));
1047 } 1047 }
1048 1048
1049 $html = ''; 1049 $html = '';
1050 $from_user = new User\Account($_POST['merge_user_from']); 1050 $from_user = new User\Account($_POST['merge_user_from']);
1051 $to_user = new User\Account($_POST['merge_user_to']); 1051 $to_user = new User\Account($_POST['merge_user_to']);
1052
1053 // These fields are skipped ONLY IN DISPLAY
1054 $skipped_fields = array( 1052 $skipped_fields = array(
1055 'ID', 1053 'ID',
1056 'id',
1057 'user_login', 1054 'user_login',
1055 'user_pass',
1056 'user_nicename',
1058 'user_email', 1057 'user_email',
1059 'member_id', 1058 'user_url',
1059 'user_registered',
1060 'user_activation_key',
1061 'user_status',
1062 'display_name',
1063 'id',
1060 'caps', 1064 'caps',
1061 'cap_key', 1065 'cap_key',
1062 'roles', 1066 'roles',
1063 'allcaps', 1067 'allcaps',
1064 'filter', 1068 'filter',
1065 'user_pass',
1066 'user_activation_key',
1067 'status', 1069 'status',
1068 'four_security_expiration', 1070 'four_security_expiration',
1069 'course_4q_approvals', 1071 'course_4q_approvals',
...@@ -1101,13 +1103,19 @@ HTML; ...@@ -1101,13 +1103,19 @@ HTML;
1101 if ($key == 'member_id' && empty($val)) { 1103 if ($key == 'member_id' && empty($val)) {
1102 continue; 1104 continue;
1103 } 1105 }
1104
1105 // Make sure we're updating the right user ID and perform update 1106 // Make sure we're updating the right user ID and perform update
1106 update_user_meta($to_user->ID, $key, $val); 1107 update_user_meta($to_user->ID, $key, $val);
1107 1108
1108 // Build a table of data 1109 // Build a table of data
1109 $html .= "\n\t<tr><td>$key: $val</td></tr>"; 1110 $html .= "\n\t<tr><td>$key: $val</td></tr>";
1110 } 1111 }
1112 if (! empty($from_user->user_email)) {
1113 // Transfer old user's profile preference email address (work, home, etc.) to new user's user_email field
1114 if (isset($from_user->profile_preference) && ! empty($from_user->profile_preference)) {
1115 $preference = strtolower($from_user->profile_preference) . '_email';
1116 _update_user(array('ID' => $to_user->ID, 'user_email' => $from_user->$preference));
1117 }
1118 }
1111 1119
1112 // Set a few meta values for the old user 1120 // Set a few meta values for the old user
1113 update_user_meta($from_user->ID, 'status', 'terminated'); 1121 update_user_meta($from_user->ID, 'status', 'terminated');
......