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"]);
if($user){
$user_id = $user->ID;
$comment["user_id"] = $user_id;
wp_update_comment($comment); //This method doesn't work
/*
* This method doesn't work either
$wpdb->update(
$wpdb->prefix.'comments',
array(
'user_id' => $user_id
),
array(
'comment_ID' => $comment_id
)
);
$wpdb->print_error();*/
}
}
}
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?