wp_delete_user()
git-svn-id: https://develop.svn.wordpress.org/trunk@2698 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
37f40b7935
commit
bcb1e84446
@ -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);
|
||||
|
||||
// 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");
|
||||
}
|
||||
wp_delete_user($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
Block a user