WordPress.org

Make WordPress Core

Changeset 2698


Ignore:
Timestamp:
07/04/2005 10:03:42 PM (16 years ago)
Author:
ryan
Message:

wp_delete_user()

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r2697 r2698  
    300300
    301301    return 1;
     302}
     303
     304function wp_delete_user($id) {
     305    global $wpdb;
     306
     307    $id = (int) $id;
     308
     309    $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
     310
     311    if ($post_ids) {
     312        $post_ids = implode(',', $post_ids);
     313       
     314        // Delete comments, *backs
     315        $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
     316        // Clean cats
     317        $wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
     318        // Clean post_meta
     319        $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids)");
     320        // Clean links
     321        $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
     322        // Delete posts
     323        $wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
     324    }
     325
     326    // FINALLY, delete user
     327    $wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id");
     328
     329    do_action('delete_user', $id);
     330
     331    return true;
    302332}
    303333
  • trunk/wp-admin/users.php

    r2636 r2698  
    136136        die(__('Can’t delete a user whose level is higher than yours.'));
    137137
    138     $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
    139     if ($post_ids) {
    140         $post_ids = implode(',', $post_ids);
    141        
    142         // Delete comments, *backs
    143         $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
    144         // Clean cats
    145         $wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
    146         // Clean post_meta
    147         $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids)");
    148         // Clean links
    149         $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
    150         // Delete posts
    151         $wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
    152     }
    153 
    154     // FINALLY, delete user
    155     $wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id");
     138    wp_delete_user($id);
     139
    156140    header('Location: users.php?deleted=true');
    157141
Note: See TracChangeset for help on using the changeset viewer.