From 29d4257fbd9c4ae9552d792b517696c01b64c16c Mon Sep 17 00:00:00 2001 From: ryan 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: http://svn.automattic.com/wordpress/trunk@10975 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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');