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:
parent
7f699e5857
commit
57c4b79b91
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -419,7 +419,7 @@ function get_users_drafts( $user_id ) {
|
|||
* @param int $reassign Optional. Reassign posts and links to new User ID.
|
||||
* @return bool True when finished.
|
||||
*/
|
||||
function wp_delete_user($id, $reassign = 'novalue') {
|
||||
function wp_delete_user( $id, $reassign = 'novalue' ) {
|
||||
global $wpdb;
|
||||
|
||||
$id = (int) $id;
|
||||
|
@ -428,11 +428,11 @@ 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) {
|
||||
foreach ($post_ids as $post_id)
|
||||
if ( $post_ids ) {
|
||||
foreach ( $post_ids as $post_id )
|
||||
wp_delete_post($post_id);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue