I want to convert all anonymous comments that have already been posted into a registered user using the username and a randomly generated password.

I really don't know where to begin with this.

I also want to convert new anonymous commenters into a registered user. If I add a hook into functions.php using register_new_user will it automatically generate a random password for the user and email them, or do I need to make a password field under the comment form as well?

Here is my comment form when a user is not registered:

enter image description here

Here is what my code for the comment form looks like:

args = array(

    'comment_field' =>  '<div class="form-group the-comment-form"><label for="comment" class="custom-avatar">' . $useravatar_custom .

      '</label><div id="' . $textareaId . '"><textarea id="comment" class="form-control" name="comment" cols="45" rows="8" aria-required="true" placeholder="Join the discussion..."></textarea></div></div>',      

    'fields' => apply_filters( 'comment_form_default_fields', array(

      'author' =>

        '<div class="form-group comments-name">' .

        '<label for="author">' . __( 'Username', 'usertheme' ) . '</label> ' .

        ( $req ? '<span class="required">*</span>' : '' ) .

        '<input id="author" name="author" class="form-control" type="text" value="' . esc_attr( $commenter['comment_author'] ) .

        '" size="30"' . $aria_req . ' /></div>',

      'email' =>

        '<div class="form-group comments-email"><label for="email">' . __( 'Email', 'usertheme' ) . '</label> ' .

        ( $req ? '<span class="required">*</span>' : '' ) .

        '<input id="email" name="email" class="form-control" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .

        '" size="30"' . $aria_req . ' /></div>'

As you see, there is a name and email required. What I want to do is make it register a new user. But I also want to generate a random password for the user.

Do I need to add a password field to the comment form? Or do I need to use the wordpress create password function? Or if I use register_new_user will it automatically generate a random password and email the user their new login details?


1 Answer 1


The register_new_user triggers after the user has been created when the register_new_user() function runs and it will give you the $id of the new user that has been created.

If you are using register_new_user() you dont need a password field, wordpress will create one a send it using the email provided to the user.

So yes, using the function will create the user and generate a password, and this logins details will be send to the user.

  • I realized this only answered only part of my question, I upvoted but can't accept because it's not a complete answer. Commented Feb 20, 2017 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.