I'm trying to update the user_id of a comment once it has been posted. It looks to see if the comment_author_email exists as a user in the users table, and if it does, attach that user to the comment.

function set_comment_author($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"]);
            $user_id = $user->ID;
            $comment["user_id"] = $user_id;
            wp_update_comment($comment); //This method doesn't work

             * This method doesn't work either
                        'user_id' => $user_id
                        'comment_ID' => $comment_id
add_action("comment_post", "set_comment_author", 10, 1);

I have done some debugging, and the action is being fired, the comment ID is coming through, and the user_id is being found. So the problem is updating the comment. Both wordpress function and database method don't work.

Any ideas?

1 Answer 1


Sorry, being stupid, i was using $comment_id, I needed $comment_ID.

The wp_update_comment() function still didn't work though, if anyone can shed some light onto that.

  • Edit your question instead of posting this as an answer.
    – Christine Cooper
    Commented Jun 6, 2013 at 14:01
  • Any luck in solving this?
    – Pete
    Commented Jul 12, 2019 at 3:46

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.