Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#20447 closed defect (bug) (fixed)

wp_delete_user( int, $user_id ) does not flush post caches

Reported by: joehoyle's profile joehoyle Owned by: ryan's profile ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.0
Component: Cache API Keywords: has-patch
Focuses: Cc:

Description

Calling wp_delete_post( 2456, 1 ) does not flush the caches for the re-assigned posts. For example:

// assuming post 123 has an author of 2
$post = get_post( 123 );

wp_delete_user( $post->post_author, 1 );

$post = get_post( 123 );
$post->post_author; // this is "2", should be "1"

This is because clean_post_cache is not called on the reassigned posts (see http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/user.php#L259).

The best way around this I can see is get the post IDs and called wp_update_post() to let code hook in to update stuff where necessary. If performance is an issue (s wp_update_post can be slow), then I think it should at least get all the post IDs and call clean_post_cache on them.

Attachments (2)

20447.patch (1.9 KB) - added by kurtpayne 12 years ago.
Use wp_update_post and wp_update_link
20447.1.patch (947 bytes) - added by kurtpayne 12 years ago.
Using clean_post_cache and clean_bookmark_cache

Download all attachments as: .zip

Change History (10)

#1 @joehoyle
12 years ago

  • Summary changed from wp_delete_post( int, $user_id ) does not flush post caches to wp_delete_user( int, $user_id ) does not flush post caches

#2 @scribu
12 years ago

  • Keywords needs-patch added

Should definitely use wp_update_post() instead of just $wpdb->update().

Last edited 12 years ago by scribu (previous) (diff)

@kurtpayne
12 years ago

Use wp_update_post and wp_update_link

#3 @kurtpayne
12 years ago

  • Cc kpayne@… added
  • Keywords has-patch added; needs-patch removed

#4 @nacin
12 years ago

  • Version changed from 3.4 to 3.0

Definitely not new — setting to an earlier version.

#6 follow-up: @nacin
12 years ago

  • Milestone changed from Awaiting Review to 3.5

Not sure I'd mind if we just clear the post cache here, rather than switching to use the API. That's a painful update to run across a lot of posts individually.

@kurtpayne
12 years ago

Using clean_post_cache and clean_bookmark_cache

#7 in reply to: ↑ 6 @kurtpayne
12 years ago

Replying to nacin:

Not sure I'd mind if we just clear the post cache here, rather than switching to use the API. That's a painful update to run across a lot of posts individually.

Agreed. Patch updated.

#8 @ryan
12 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21798]:

When reassigning posts and links during user deletion, clear the post and link caches. Props kurtpayne. fixes #20447

Note: See TracTickets for help on using tickets.