From 23d6f231f98efe4a28e12ec9063430b93dedb69d Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 17 Apr 2009 02:13:00 +0000 Subject: [PATCH] Use API to delete links when deleting a user. Props TimButterfield, scohoust. fixes #7774 git-svn-id: https://develop.svn.wordpress.org/trunk@10975 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/user.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 15397a603a..1f04875f6c 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -411,7 +411,8 @@ function wp_delete_user($id, $reassign = 'novalue') { global $wpdb; $id = (int) $id; - + $user = new WP_User($id); + // allow for transaction statement do_action('delete_user', $id); @@ -424,7 +425,13 @@ function wp_delete_user($id, $reassign = 'novalue') { } // Clean links - $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->links WHERE link_owner = %d", $id) ); + $link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) ); + + if ( $link_ids ) { + foreach ( $link_ids as $link_id ) + wp_delete_link($link_id); + } + } else { $reassign = (int) $reassign; $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $id) ); @@ -436,8 +443,6 @@ function wp_delete_user($id, $reassign = 'novalue') { $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) ); $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $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');