I'm creating a new user once they leave a comment, i am doing this with wp_insert_user

function create_comment_user($comment_ID){ global $wpdb;

$comment = get_comment($comment_ID, ARRAY_A);
if($comment["user_id"] == 0){
    $user = get_user_by('email', $comment["comment_author_email"]);
    if(! $user){
        $new_id = wp_insert_user(array(
                'user_pass' => wp_generate_password(),
                'user_login' => $comment["comment_author_email"],
                'user_email' => $comment["comment_author_email"],
                'user_nicename' => strtolower(str_replace(' ', '-', $_POST['author'])).'-'.strtolower(str_replace(' ', '-', $_POST['author_last'])),
                'display_name' => ($_POST['author']).' '.($_POST['author_last']),
                'first_name' => ($_POST['author']),
                'last_name' => ($_POST['author_last']),
                'role'      => 'Subscriber'
            wp_new_user_notification( $new_id );
add_action("comment_post", "create_comment_user", 10, 1);

The email confirmation does not get sent, but the user is being created. Any ideas why?

  • Did you check if the user is created? $new_id can also be a WP_Error object, which evaluates to true in your condition – onetrickpony Jul 2 '13 at 12:24
  • $new_id is returning an int referring to a new user, so this part seems to work.. – user195257 Jul 2 '13 at 12:42
  • Found the problem, was a silly mistake in my wp_new_user_notifcation that was returning before the mail was sent. Please delete this question – user195257 Jul 2 '13 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.