0eca07ae by Marty Penner

Initial fix for merge_users calls to wp_delete_user interfering with ajax calls

1 parent 0b65d7a2
...@@ -246,4 +246,4 @@ jQuery(function($) { ...@@ -246,4 +246,4 @@ jQuery(function($) {
246 246
247 247
248 248
249 });
...\ No newline at end of file ...\ No newline at end of file
249 });
......
...@@ -25,6 +25,7 @@ use WP_User; ...@@ -25,6 +25,7 @@ use WP_User;
25 const OPTION_NAME = "user_options"; 25 const OPTION_NAME = "user_options";
26 const CAPABILITY = "manage_cbv_users"; 26 const CAPABILITY = "manage_cbv_users";
27 27
28
28 CBV\load('Invoice'); 29 CBV\load('Invoice');
29 CBV\load('User'); 30 CBV\load('User');
30 Tools\import('HTML'); 31 Tools\import('HTML');
...@@ -1029,6 +1030,8 @@ HTML; ...@@ -1029,6 +1030,8 @@ HTML;
1029 } 1030 }
1030 1031
1031 $unchanged_html = ''; 1032 $unchanged_html = '';
1033 $html = '';
1034 $remove_user_html = '';
1032 $from_user = new User\Account($_POST['merge_user_from']); 1035 $from_user = new User\Account($_POST['merge_user_from']);
1033 $to_user = new User\Account($_POST['merge_user_to']); 1036 $to_user = new User\Account($_POST['merge_user_to']);
1034 $to_user_array = array(); 1037 $to_user_array = array();
...@@ -1064,11 +1067,15 @@ HTML; ...@@ -1064,11 +1067,15 @@ HTML;
1064 1067
1065 // Delete the old user if the checkbox is set 1068 // Delete the old user if the checkbox is set
1066 if (isset($_POST['delete_old_user']) && $_POST['delete_old_user'] == 'yes') { 1069 if (isset($_POST['delete_old_user']) && $_POST['delete_old_user'] == 'yes') {
1067 @wp_delete_user($from_user->ID); 1070 $username = $from_user->user_login;
1071 if (@wp_delete_user($from_user->ID)) {
1072 $remove_user_html = "<h6>Deleted user $username.</h6>";
1073 } else {
1074 $remove_user_html = '<h6>Could not delete user.</h6>';
1075 }
1068 } 1076 }
1069 1077
1070 // Build a set of nested html lists that display the fields (goes 3 levels deep; bloody ugly, but works) 1078 // Build a set of nested html lists that display the fields (goes 3 levels deep; bloody ugly, but works)
1071 $html = '';
1072 foreach ($to_user_array as $key => $val) { 1079 foreach ($to_user_array as $key => $val) {
1073 $html_l2 = ''; 1080 $html_l2 = '';
1074 if (is_array($val)) { 1081 if (is_array($val)) {
...@@ -1090,7 +1097,21 @@ HTML; ...@@ -1090,7 +1097,21 @@ HTML;
1090 $html .= "<li>$key: $val</li>"; 1097 $html .= "<li>$key: $val</li>";
1091 } 1098 }
1092 } 1099 }
1093 $html = $unchanged_html . '<h6>Changed:</h6><ul>' . $html . '</ul>'; 1100
1101 if (! empty($remove_user_html)) {
1102 $initial = $remove_user_html;
1103 } else {
1104 $initial = $unchanged_html;
1105 }
1106 $html = //'<h4><a href="/wp-admin/admin-ajax.php?ajax=yes&action=build_user_remove&uid=' .
1107 //$from_user->ID .
1108 //'" rel="' .
1109 //$from_user->ID .
1110 //'" class="remove-user">Remove old user</a></h4>' .
1111 $initial .
1112 '<h6>Changed:</h6><ul>' .
1113 $html .
1114 '</ul>';
1094 1115
1095 $return = array( 1116 $return = array(
1096 'success' => 'true', 1117 'success' => 'true',
......
...@@ -130,6 +130,7 @@ h4 { ...@@ -130,6 +130,7 @@ h4 {
130 <input type="hidden" value="from" name="which_user_search" /> 130 <input type="hidden" value="from" name="which_user_search" />
131 <input type="hidden" value="no" name="do_search" /> 131 <input type="hidden" value="no" name="do_search" />
132 <input type="hidden" value="no" name="do_merge" /> 132 <input type="hidden" value="no" name="do_merge" />
133 <input type="hidden" value="0" name="uid" />
133 <input type="checkbox" value="yes" name="delete_old_user" /> 134 <input type="checkbox" value="yes" name="delete_old_user" />
134 <label for="delete_old_user">Delete old user?</label> 135 <label for="delete_old_user">Delete old user?</label>
135 <input type="button" value="Merge Users" name="btn_merge" /> 136 <input type="button" value="Merge Users" name="btn_merge" />
......