Introduce clean_user_cache(). fixes #11761

git-svn-id: http://svn.automattic.com/wordpress/trunk@12766 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-01-19 19:23:11 +00:00
parent 7f699e5857
commit 57c4b79b91
3 changed files with 29 additions and 13 deletions

View File

@ -101,6 +101,7 @@ function wpmu_delete_blog($blog_id, $drop = false) {
restore_current_blog();
}
// @todo Merge with wp_delete_user() ?
function wpmu_delete_user($id) {
global $wpdb;
@ -131,8 +132,10 @@ function wpmu_delete_user($id) {
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) );
wp_cache_delete($id, 'users');
wp_cache_delete($user->user_login, 'userlogins');
clean_user_cache($id);
// allow for commit transaction
do_action('deleted_user', $id);
return true;
}
@ -449,8 +452,8 @@ function refresh_user_details($id) {
if ( !$user = get_userdata( $id ) )
return false;
wp_cache_delete($id, 'users');
wp_cache_delete($user->user_login, 'userlogins');
clean_user_cache($id);
return $id;
}

View File

@ -428,7 +428,7 @@ function wp_delete_user($id, $reassign = 'novalue') {
// allow for transaction statement
do_action('delete_user', $id);
if ($reassign == 'novalue') {
if ( 'novalue' === $reassign || null === $reassign ) {
$post_ids = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id) );
if ( $post_ids ) {
@ -443,7 +443,6 @@ function wp_delete_user($id, $reassign = 'novalue') {
foreach ( $link_ids as $link_id )
wp_delete_link($link_id);
}
} else {
$reassign = (int) $reassign;
$wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) );
@ -459,10 +458,7 @@ function wp_delete_user($id, $reassign = 'novalue') {
$wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = $id AND meta_key = '{$level_key}'");
}
wp_cache_delete($id, 'users');
wp_cache_delete($user->user_login, 'userlogins');
wp_cache_delete($user->user_email, 'useremail');
wp_cache_delete($user->user_nicename, 'userslugs');
clean_user_cache($id);
// allow for commit transaction
do_action('deleted_user', $id);

View File

@ -735,4 +735,21 @@ function sanitize_user_field($field, $value, $user_id, $context) {
return $value;
}
/**
* Clean all user caches
*
* @since 3.0
*
* @param int $id User ID
* @return void
*/
function clean_user_cache($id) {
$user = new WP_User($id);
wp_cache_delete($id, 'users');
wp_cache_delete($user->user_login, 'userlogins');
wp_cache_delete($user->user_email, 'useremail');
wp_cache_delete($user->user_nicename, 'userslugs');
}
?>