Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Eddie Krebs

    (@ekrebs)

    gomez, try wpmu_delete_user. Pretty obvious once you know about it.

    http://codex.wordpress.org/Function_Reference/wpmu_delete_user

    Thread Starter Eddie Krebs

    (@ekrebs)

    Tim, this makes perfect sense and is exactly the information I was digging for. Thanks a ton!

    Thread Starter Eddie Krebs

    (@ekrebs)

    Hi ShinichiN. Yes, you almost certainly could hook into the deleted_user action and run the delete code yourself. That’s a good workaround for someone in my situation, thanks.

    I think the best solution is to propose this as a bug and see what the core developers say. I just wanted to pass it through the forums first and see if I missed something obvious.

    Thread Starter Eddie Krebs

    (@ekrebs)

    I’ll take your advice and look into using hooks again instead of a custom user editor. I’m not convinced yet this is the proper method for us because of the scope of our application, but I’ll look at BuddyPress closely and see if we just missed the boat somehow.

    None of this changes the fact that the wp_delete_user method seems to fail. When logged in as a super admin, running this method returns true but does not actually delete the user. The key question is this: does this method work for anyone else in a multisite setup, or is it broken?

    Thread Starter Eddie Krebs

    (@ekrebs)

    I do understand that. We’re not using WordPress as a multi-blog platform, but as an engine to allow customers to create multiple websites with different functionality for their employees. It’s very specialized. If I hooked into the user editor, I would be removing just about everything already there and adding my own functionality in the hooks. It sure seems more efficient if I write half the code and get all the functionality I need.

    WordPress has functions like wp_delete_user and wp_insert_user for just this purpose.

    I get what you’re saying, and I’ve evaluated the pros and cons of this approach. I believe the custom screen is the best for our application.

    To answer your follow up suspicion, I am logged in as the super admin. There are two users in the test environment: the super admin and the user to be deleted. There are two sites (blogs), the initial blog and one I created (blog_id 4 in this case). I am logged into Blog ID 4 as super admin. The user is a Subscriber of blog_id 4.

    Thread Starter Eddie Krebs

    (@ekrebs)

    Just to follow up, the code I pasted from user.php is confusing me because I literally do not see the line of code to delete the user. Maybe that code is hidden in some called procedure that I missed?

    The else statement below runs if is_multisite is true. I see the query to delete the user meta, but no code to delete the user from the wp_users table. If that code is actually missing it would produce my issue.

    } else {
        $level_key = $wpdb->get_blog_prefix() . 'capabilities';
        $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = $id AND meta_key = '{$level_key}'");
    }

    I highly doubt I found a bug in WordPress. I just can’t find where the “delete from $wpdb->users” code is.

    Thread Starter Eddie Krebs

    (@ekrebs)

    Hi Ipstenu, thanks for the response.

    I am using a custom user creation screen, with a checkbox to auto-create a blog for the created user. This auto-creation creates some custom site meta data and associates the user with the site.

    The code logic creates the user, then attempts to create the site. If the site creation fails for some reason, it deletes the user and returns the error to the admin. Only, the code doesn’t delete the user as expected.

    Here is the relevant code. $aws_site returns null (site creation fails), and the code inside the if statement gets executed. The $user_id is valid and wp_delete_user returns 1. However, the user is still in the database, and the “deleted” field remains 0 in the wp_users table.

    $site_id = $aws_site->create( $_POST[ 'subdomain' ], $user_id );
    
    if ( is_null( $site_id ) ) {
        $msg = $aws_site->error_message;
        wp_delete_user( $user_id ); // roll back user creation
    }
Viewing 7 replies - 1 through 7 (of 7 total)