Skip to content

Commit 2deb956

Browse files
committed
When deleting via User List Table, don't prompt for re-attribution if the user(s) do(es) not have any posts.
Props rajnikmit, wojtek.szkutnik, benjmay, wonderboymusic. Fixes WordPress#6405. git-svn-id: https://develop.svn.wordpress.org/trunk@34000 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9473a47 commit 2deb956

2 files changed

Lines changed: 46 additions & 34 deletions

File tree

src/wp-admin/includes/user.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,22 @@ function default_password_nag() {
446446
printf( '<a href="%s" id="default-password-nag-no">' . __('No thanks, do not remind me again') . '</a>', '?default_password_nag=0' );
447447
echo '</p></div>';
448448
}
449+
450+
/**
451+
* @since 3.5.0
452+
* @access private
453+
*/
454+
function delete_users_add_js() { ?>
455+
<script>
456+
jQuery(document).ready( function($) {
457+
var submit = $('#submit').prop('disabled', true);
458+
$('input[name="delete_option"]').one('change', function() {
459+
submit.prop('disabled', false);
460+
});
461+
$('#reassign_user').focus( function() {
462+
$('#delete_option1').prop('checked', true).trigger('change');
463+
});
464+
});
465+
</script>
466+
<?php
467+
}

src/wp-admin/users.php

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,6 @@
8080

8181
$update = '';
8282

83-
/**
84-
* @since 3.5.0
85-
* @access private
86-
*/
87-
function delete_users_add_js() { ?>
88-
<script>
89-
jQuery(document).ready( function($) {
90-
var submit = $('#submit').prop('disabled', true);
91-
$('input[name=delete_option]').one('change', function() {
92-
submit.prop('disabled', false);
93-
});
94-
$('#reassign_user').focus( function() {
95-
$('#delete_option1').prop('checked', true).trigger('change');
96-
});
97-
});
98-
</script>
99-
<?php
100-
}
101-
10283
switch ( $wp_list_table->current_action() ) {
10384

10485
/* Bulk Dropdown menu Role changes */
@@ -215,7 +196,15 @@ function delete_users_add_js() { ?>
215196
else
216197
$userids = array_map( 'intval', (array) $_REQUEST['users'] );
217198

218-
add_action( 'admin_head', 'delete_users_add_js' );
199+
$users_posts = new WP_Query( array(
200+
'post_type' => 'any',
201+
'author' => implode( ',', $userids ),
202+
'posts_per_page' => 1
203+
) );
204+
205+
if ( $users_posts->have_posts() ) {
206+
add_action( 'admin_head', 'delete_users_add_js' );
207+
}
219208

220209
include( ABSPATH . 'wp-admin/admin-header.php' );
221210
?>
@@ -251,20 +240,24 @@ function delete_users_add_js() { ?>
251240
}
252241
?>
253242
</ul>
254-
<?php if ( $go_delete ) : ?>
255-
<?php if ( 1 == $go_delete ) : ?>
256-
<fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
257-
<?php else : ?>
258-
<fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
259-
<?php endif; ?>
260-
<ul style="list-style:none;">
261-
<li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
262-
<?php _e('Delete all content.'); ?></label></li>
263-
<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
264-
<?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
265-
wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
266-
</ul></fieldset>
267-
<?php
243+
<?php if ( $go_delete ) :
244+
245+
if ( ! $users_posts->have_posts() ) : ?>
246+
<input type="hidden" name="delete_option" value="delete" />
247+
<?php else: ?>
248+
<?php if ( 1 == $go_delete ) : ?>
249+
<fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
250+
<?php else : ?>
251+
<fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
252+
<?php endif; ?>
253+
<ul style="list-style:none;">
254+
<li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
255+
<?php _e('Delete all content.'); ?></label></li>
256+
<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
257+
<?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
258+
wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
259+
</ul></fieldset>
260+
<?php endif;
268261
/**
269262
* Fires at the end of the delete users form prior to the confirm button.
270263
*

0 commit comments

Comments
 (0)