• Hello everyone, I face this difficulty in a multisite plugin I develop and I need your help, if you please.

    I’m building a front-end form that allows a user (with the proper permissions) to create another one. For that, I use the hook admin_post_ {my_function} and my_function is supposed to do the registration work after receiving the necessary information in POST.

    I have found many ways to do this registration but I have not found the right one ??

    What I want for my front-end: I’d like that an authorized user could “pre-register” a new user, in the ‘signups‘ table, with a temporary password (either received by the form or generated by wordpress), that is the common way to register a new user in the admin part of WP. (the temporary user stays in the “signups” table until he receive a mail, log on, change his password, and then, be transfered to the “users” table).

    I found several possibilities but none of them does exactly this:

    1 – I have tried with wp_create_user ($ username, $ passwd, $ email): it works but it creates a user directly in the users table. Then, we can assign a role (with the created $id) and we can send a notification with wp_new_user_notification ($ username, $ passwd)

    2 – I have tried with register_new_user ($ username,$email): it’s almost the same, except that WP creates a passwd.

    3 – We also could use wp_insert_user($ args), as it offers a good list of parameters arguments, but none offers the possibility to choose ‘temporary’ or something like this.

    I probably miss something important…Would you know a way to make this ?
    (I have tried to read the wp-admin/user-new.php in order to mimic it, but I got rapidly lost !)

    thank you in advance for any help…
    Pierre

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter bastringue

    (@bastringue)

    One step beyond…still not perfect but that may help :

    Reading this, i have tried the following:

    wpmu_signup_user( $new_user_login, $new_user_email, array( ‘add_to_blog’ => $blogid, ‘new_role’ => $role ) );
    $key = $wpdb->get_var( $wpdb->prepare( “SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s”, $new_user_login, $new_user_email ) );
    $ret = wpmu_activate_signup( $key );

    The last line permits to get the id back (in the $ret array)

    It’s better because I find an entry in the signups table now, but strangely, I can find another entry in the user table for this user…maybe due to the wpmu_activate_signup($key) ? I don’t know…

    Still searching…
    Pierre

    Thread Starter bastringue

    (@bastringue)

    I (try to) summarize for clarity :
    Reading this, i have tried the following:

    wpmu_signup_user( $new_user_login, $new_user_email, array( ‘add_to_blog’ => $blogid, ‘new_role’ => $role ) );

    This creates a user in the signups table (Ok).

    Unfortunately, the user doesn’t have a real user_id at this stage, as long as he has not confirmed his registration.

    So my problem has changed a little : The authorized user was supposed to be able to create a new user (this is OK now) and he was also supposed to “prepare” different things for this future user, namely create various entries for him in various other tables, and so, he needs to have a user_id.

    the same link given above proposes to add these 2 lines :
    $key = $wpdb->get_var( $wpdb->prepare( “SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s”, $new_user_login, $new_user_email ) );
    $ret = wpmu_activate_signup( $key );

    These lines activate the temporary registration by picking the activation key in the signup table and confirm the registration !!!
    Of course, once activated, it’s easy to get the id but I am afraid this completely messes up the confirmation process for the guessed user (?)

    Pierre

    Pierre

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘register a user (programmatically) multisite, on the signups table’ is closed to new replies.