Opened 9 years ago
Closed 9 years ago
#34993 closed defect (bug) (fixed)
Deleting a user no longer asks what to do with their content
Reported by: | beerallica | Owned by: | dd32 |
---|---|---|---|
Milestone: | 4.4.1 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Users | Keywords: | has-patch commit fixed-major |
Focuses: | administration | Cc: |
Description
The process that deletes a user seems to only notice posts, and ignore other post_types, so it doesn't ask me if I want to attribute their content to other users if that content is of custom post_type.
On a certain installation, trying to delete a user that has zero posts, but 10 bbpress topics and 19 replies. the following query:
$users_posts = new WP_Query( array( 'post_type' => 'any', 'author' =>$user_id, 'posts_per_page' => 1 ) ); var_dump( $users_posts->found_posts, $users_posts->have_posts() );
returns
int(0) bool(false)
Attachments (2)
Change History (16)
This ticket was mentioned in Slack in #bbpress by swissspidy. View the logs.
9 years ago
#6
@
9 years ago
- Keywords has-patch needs-testing added; needs-patch removed
34993.patch is a possible solution that uses a custom SQL query instead of WP_Query
. Wondering if we even need to check for post statuses.
@beerallica Would you mind testing this patch? Thanks!
#7
@
9 years ago
I don't think we need a check for post_statuses. wp_delete_user (https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/user.php#L284) doesn't differentiate between them, so it's more consistent to not use it here. Plus it's much faster. :)
#8
@
9 years ago
- Keywords commit added; needs-testing removed
Just tested 34993.2.patch and works for me, agree with no need for post statuses.
This ticket was mentioned in Slack in #core by johnbillion. View the logs.
9 years ago
#11
@
9 years ago
- Owner changed from netweb to dd32
- Status changed from assigned to accepted
A few small things:
- There's no need to do the
GROUP BY
, and we don't even need theCOUNT(*)
. We just want to know if any of them have posts. It's a lot more efficient to simply doSELECT ID FROM {$wpdb->posts} WHERE post_author IN(1,2,3) LIMIT 1
as it'll return the truthy value as soon as it finds any content. - "Content" in the realm of
wp_delete_user()
is also Links/Bookmarks, so we should also check that, [34000] didn't take that into consideration. Better to take that into consideration than have a users old content go missing.
Confirming, I noticed this same thing yesterday whilst cleaning up some users in a bbPress install.
This came from [34000]/#6405, the cause is wp-admin/users.php#L215 and
'post_type' => 'any
because withWP_Query
if the post type is set toany
and the post type was registered withexclude_from_search
astrue
(which bbPress does for all 3 CPT's registered) then WP_Query excludes these posts from the query. Hence the "Attribute content to another author" is not shown because the bbPress posts are excluded from the search.https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
Note: Also need to check how this has or has not changed for Multisite (/wp-admin/includes/ms.php#L1057)