I manage a user registration process (on a multisite WP).

However, some of my users can create new ones in a front page. If you look at this post you will find out the 3 stages for this:

  1. Use wpmu_signup_user() to add an entry for a new (future) user in the signups table (you can keep WP from sending a notification mail at this stage, if desired, with the right hook)
  2. Use a SQL query to get the activation_key generated in this entry of the signups table for this user
  3. Use wpmu_activate_signup($key) to create an entry in the users table

This works fine, but once the user is created (with an entry in the users table) I would need to delete that entry which still is in the signups table and is useless. Someone would know how to do this wp_properly or should I make a delete query?

1 Answer
1

You are correct about the row not having much use outside of a two day threshold where a user doesn’t activate their account.

I took a look at the codebase and can confirm there is no API function for removing a signup entry. The only code that removes a signup is the wpmu_validate_user_signup() function. It checks against current signups for the same user_login and user_email. If either of those exist, it checks to see if that user registered within the last two days. They have two days to activate their account, or that user_login or user_email becomes available to someone else.

What I would do is hook into the wp_activate_user hook to remove it immediately.

add_action( 'wpmu_activate_user', function( $user_id, $password, $meta ) {
    global $wpdb;
    // Sadly the user email isn't passed into the action
    $user = get_user_by( 'id', $user_id );
    if( $user ){
        $wpdb->delete( $wpdb->signups, array( 'user_email' => $user->user_email ) );
    }
}, 0, 3);

Leave a Reply

Your email address will not be published. Required fields are marked *