wp_delete_user()
git-svn-id: http://svn.automattic.com/wordpress/trunk@2698 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cbce881c2b
commit
a79476f1e7
|
@ -301,6 +301,36 @@ function wp_delete_category($cat_ID) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
function wp_delete_user($id) {
|
||||
global $wpdb;
|
||||
|
||||
$id = (int) $id;
|
||||
|
||||
$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
|
||||
|
||||
if ($post_ids) {
|
||||
$post_ids = implode(',', $post_ids);
|
||||
|
||||
// Delete comments, *backs
|
||||
$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
|
||||
// Clean cats
|
||||
$wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
|
||||
// Clean post_meta
|
||||
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids)");
|
||||
// Clean links
|
||||
$wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
|
||||
// Delete posts
|
||||
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
|
||||
}
|
||||
|
||||
// FINALLY, delete user
|
||||
$wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id");
|
||||
|
||||
do_action('delete_user', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function url_shorten ($url) {
|
||||
$short_url = str_replace('http://', '', stripslashes($url));
|
||||
$short_url = str_replace('www.', '', $short_url);
|
||||
|
|
|
@ -135,24 +135,8 @@ case 'delete':
|
|||
if ($user_level <= $usertodelete_level)
|
||||
die(__('Can’t delete a user whose level is higher than yours.'));
|
||||
|
||||
$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
|
||||
if ($post_ids) {
|
||||
$post_ids = implode(',', $post_ids);
|
||||
wp_delete_user($id);
|
||||
|
||||
// Delete comments, *backs
|
||||
$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
|
||||
// Clean cats
|
||||
$wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
|
||||
// Clean post_meta
|
||||
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids)");
|
||||
// Clean links
|
||||
$wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
|
||||
// Delete posts
|
||||
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
|
||||
}
|
||||
|
||||
// FINALLY, delete user
|
||||
$wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id");
|
||||
header('Location: users.php?deleted=true');
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue