|
206 | 206 | continue; |
207 | 207 | } |
208 | 208 |
|
209 | | - switch ( $_REQUEST['delete_option'] ) { |
| 209 | + switch ( $_REQUEST['delete_option'][ $id ] ) { |
210 | 210 | case 'delete': |
211 | 211 | wp_delete_user( $id ); |
212 | 212 | break; |
213 | 213 | case 'reassign': |
214 | | - wp_delete_user( $id, $_REQUEST['reassign_user'] ); |
| 214 | + wp_delete_user( $id, $_REQUEST['reassign_user'][ $id ] ); |
215 | 215 | break; |
216 | 216 | } |
217 | 217 |
|
|
299 | 299 | $user_ids = array_diff( $user_ids, array( $current_user->ID ) ); |
300 | 300 | } |
301 | 301 |
|
302 | | - /** |
303 | | - * Filters whether the users being deleted have additional content |
304 | | - * associated with them outside of the `post_author` and `link_owner` relationships. |
305 | | - * |
306 | | - * @since 5.2.0 |
307 | | - * |
308 | | - * @param bool $users_have_additional_content Whether the users have additional content. Default false. |
309 | | - * @param int[] $user_ids Array of IDs for users being deleted. |
310 | | - */ |
311 | | - $users_have_content = (bool) apply_filters( 'users_have_additional_content', false, $user_ids ); |
312 | | - |
313 | | - if ( $user_ids && ! $users_have_content ) { |
314 | | - if ( $wpdb->get_var( |
315 | | - "SELECT ID FROM {$wpdb->posts} |
316 | | - WHERE post_author IN( " . implode( ',', $user_ids ) . ' ) |
317 | | - LIMIT 1' |
318 | | - ) ) { |
319 | | - $users_have_content = true; |
320 | | - } elseif ( $wpdb->get_var( |
321 | | - "SELECT link_id FROM {$wpdb->links} |
322 | | - WHERE link_owner IN( " . implode( ',', $user_ids ) . ' ) |
323 | | - LIMIT 1' |
324 | | - ) ) { |
325 | | - $users_have_content = true; |
326 | | - } |
327 | | - } |
328 | | - |
329 | | - if ( $users_have_content ) { |
330 | | - add_action( 'admin_head', 'delete_users_add_js' ); |
331 | | - } |
332 | | - |
333 | 302 | require_once ABSPATH . 'wp-admin/admin-header.php'; |
334 | 303 | ?> |
335 | | - <form method="post" name="updateusers" id="updateusers"> |
| 304 | + <form method="post" name="updateusers" id="updateusers" class="delete-and-reassign-users-form"> |
336 | 305 | <?php wp_nonce_field( 'delete-users' ); ?> |
337 | 306 | <?php echo $referer; ?> |
338 | 307 |
|
|
359 | 328 | <ul> |
360 | 329 | <?php |
361 | 330 | $go_delete = 0; |
| 331 | + $users_have_content = false; |
362 | 332 |
|
363 | 333 | foreach ( $all_user_ids as $id ) { |
364 | 334 | $user = get_userdata( $id ); |
|
384 | 354 | $id, |
385 | 355 | $user->user_login |
386 | 356 | ); |
| 357 | + |
| 358 | + /** |
| 359 | + * Filters whether the users being deleted have additional content |
| 360 | + * associated with them outside of the `post_author` and `link_owner` relationships. |
| 361 | + * |
| 362 | + * @since 5.2.0 |
| 363 | + * |
| 364 | + * @param bool $users_have_additional_content Whether the users have additional content. Default false. |
| 365 | + * @param int[] $user_ids Array of IDs for users being deleted. |
| 366 | + */ |
| 367 | + $user_has_content = (bool) apply_filters( 'users_have_additional_content', false, array( $id ) ); |
| 368 | + |
| 369 | + if ( ! $user_has_content ) { |
| 370 | + if ( $wpdb->get_var( |
| 371 | + $wpdb->prepare( |
| 372 | + "SELECT ID FROM {$wpdb->posts} |
| 373 | + WHERE post_author = %d |
| 374 | + LIMIT 1", |
| 375 | + $id |
| 376 | + ) |
| 377 | + ) ) { |
| 378 | + $user_has_content = true; |
| 379 | + } elseif ( $wpdb->get_var( |
| 380 | + $wpdb->prepare( |
| 381 | + "SELECT link_id FROM {$wpdb->links} |
| 382 | + WHERE link_owner = %d |
| 383 | + LIMIT 1", |
| 384 | + $id |
| 385 | + ) |
| 386 | + ) ) { |
| 387 | + $user_has_content = true; |
| 388 | + } |
| 389 | + } |
| 390 | + |
| 391 | + if ( ! $user_has_content ) { |
| 392 | + ?> |
| 393 | + <input type="hidden" name="delete_option[<?php echo esc_attr( $id ); ?>]" value="delete" required /> |
| 394 | + <p><legend><?php _e( 'This user does not have any content.' ); ?></legend></p> |
| 395 | + <?php |
| 396 | + } else { |
| 397 | + ?> |
| 398 | + <fieldset> |
| 399 | + <p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p> |
| 400 | + |
| 401 | + <ul style="list-style:none;"> |
| 402 | + <li> |
| 403 | + <input type="radio" id="delete_option_<?php echo esc_attr( $id ); ?>" name="delete_option[<?php echo esc_attr( $id ); ?>]" value="delete" required /> |
| 404 | + <label for="delete_option_<?php echo esc_attr( $id ); ?>"><?php _e( 'Delete all content.' ); ?></label> |
| 405 | + </li> |
| 406 | + <li> |
| 407 | + <input type="radio" id="reassign_option_<?php echo esc_attr( $id ); ?>" name="delete_option[<?php echo esc_attr( $id ); ?>]" value="reassign" required /> |
| 408 | + <label for="reassign_option_<?php echo esc_attr( $id ); ?>"><?php _e( 'Attribute all content to:' ); ?></label> |
| 409 | + <?php |
| 410 | + wp_dropdown_users( |
| 411 | + array( |
| 412 | + 'show_option_none' => __( 'Select a user' ), |
| 413 | + 'name' => 'reassign_user[' . $id . ']', |
| 414 | + 'id' => 'reassign_user_' . $id, |
| 415 | + 'exclude' => $user_ids, |
| 416 | + 'show' => 'display_name_with_login', |
| 417 | + ) |
| 418 | + ); |
| 419 | + ?> |
| 420 | + </li> |
| 421 | + </ul> |
| 422 | + </fieldset> |
| 423 | + <?php |
| 424 | + $users_have_content = true; |
| 425 | + } |
| 426 | + |
387 | 427 | echo "</li>\n"; |
388 | 428 |
|
389 | 429 | ++$go_delete; |
|
394 | 434 |
|
395 | 435 | <?php |
396 | 436 | if ( $go_delete ) : |
397 | | - |
398 | | - if ( ! $users_have_content ) : |
399 | | - ?> |
400 | | - <input type="hidden" name="delete_option" value="delete" /> |
401 | | - <?php else : ?> |
402 | | - <fieldset> |
403 | | - <?php if ( 1 === $go_delete ) : ?> |
404 | | - <p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p> |
405 | | - <?php else : ?> |
406 | | - <p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p> |
407 | | - <?php endif; ?> |
408 | | - |
409 | | - <ul style="list-style:none;"> |
410 | | - <li> |
411 | | - <input type="radio" id="delete_option0" name="delete_option" value="delete" /> |
412 | | - <label for="delete_option0"><?php _e( 'Delete all content.' ); ?></label> |
413 | | - </li> |
414 | | - <li> |
415 | | - <input type="radio" id="delete_option1" name="delete_option" value="reassign" /> |
416 | | - <label for="delete_option1"><?php _e( 'Attribute all content to:' ); ?></label> |
417 | | - <?php |
418 | | - wp_dropdown_users( |
419 | | - array( |
420 | | - 'name' => 'reassign_user', |
421 | | - 'exclude' => $user_ids, |
422 | | - 'show' => 'display_name_with_login', |
423 | | - ) |
424 | | - ); |
425 | | - ?> |
426 | | - </li> |
427 | | - </ul> |
428 | | - </fieldset> |
429 | | - <?php |
430 | | - endif; |
431 | | - |
432 | 437 | /** |
433 | 438 | * Fires at the end of the delete users form prior to the confirm button. |
434 | 439 | * |
|
0 commit comments