| @@ -149,9 +149,25 @@ | ||
| 149 | 149 | if ( ! function_exists( 'wp_delete_user' ) ) { |
| 150 | 150 | require_once ABSPATH . 'wp-admin/includes/user.php'; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $deleted = wp_delete_user( (int) $user_id, $reassign ); | |
| 153 | + // On multisite `wp_delete_user()` only removes the user from the | |
| 154 | + // CURRENT site — the network account (and the agent's meta with | |
| 155 | + // it) lives on. The agent's whole identity is its wp user, so | |
| 156 | + // deleting the agent means the network-wide delete. | |
| 157 | + if ( is_multisite() ) { | |
| 158 | + if ( ! function_exists( 'wpmu_delete_user' ) ) { | |
| 159 | + require_once ABSPATH . 'wp-admin/includes/ms.php'; | |
| 160 | + } | |
| 161 | + if ( null !== $reassign ) { | |
| 162 | + // `wpmu_delete_user()` has no reassign parameter; hand the | |
| 163 | + // current site's content over before the user goes. | |
| 164 | + wp_delete_user( (int) $user_id, $reassign ); | |
| 165 | + } | |
| 166 | + $deleted = wpmu_delete_user( (int) $user_id ); | |
| 167 | + } else { | |
| 168 | + $deleted = wp_delete_user( (int) $user_id, $reassign ); | |
| 169 | + } | |
| 154 | 170 | if ( ! $deleted ) { |
| 155 | 171 | return new WP_Error( |
| 156 | 172 | 'openstation_agent_delete_failed', |
| 157 | 173 | __( 'Could not delete the agent user.', 'desktop-mode' ) |