Users: When determining whether to show the reassign content option during user delete, don't rely upon `WP_Query` as it doesn't return all forms of content `wp_delete_user()` operates on.

This restores the reassign form when a user has a non-public post type or links assigned to them.

Props swissspidy & tharsheblows for initial patches.
Fixes #34993 for trunk.


git-svn-id: https://develop.svn.wordpress.org/trunk@36068 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2015-12-23 04:45:42 +00:00
parent 83f93e5e70
commit ec7fa69ef4
1 changed files with 8 additions and 7 deletions

View File

@ -211,13 +211,14 @@ case 'delete':
else
$userids = array_map( 'intval', (array) $_REQUEST['users'] );
$users_posts = new WP_Query( array(
'post_type' => 'any',
'author' => implode( ',', $userids ),
'posts_per_page' => 1
) );
$users_have_content = false;
if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . " ) LIMIT 1" ) ) {
$users_have_content = true;
} elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . " ) LIMIT 1" ) ) {
$users_have_content = true;
}
if ( $users_posts->have_posts() ) {
if ( $users_have_content ) {
add_action( 'admin_head', 'delete_users_add_js' );
}
@ -257,7 +258,7 @@ case 'delete':
</ul>
<?php if ( $go_delete ) :
if ( ! $users_posts->have_posts() ) : ?>
if ( ! $users_have_content ) : ?>
<input type="hidden" name="delete_option" value="delete" />
<?php else: ?>
<?php if ( 1 == $go_delete ) : ?>