[Solved] Guest user author stats lost when registering and using same email  


thepsir
Posts: 1
Customer
(@thepsir)
Member
Joined: 5 months ago

Hello, i am here to propose a sollution to anyone facing this problem.

Our sites have communities that was guest based, and the author information was showing up based on guest email. 
Now, we allowed register/login functions to our users, and when they register using the same email, the plugin shows only the comments made from the current (new user) user id.
To prevent this from happening, we made the following modifications on the addon code:

1) plugins/wpdiscuz-comment-author-info/includes/wcai-helper.php
Change line 167 from
$allComments = $this->dbManager->getAuthorAllComments($user->ID);
to
$allComments = $this->dbManager->getAuthorAllComments($user->ID,$user->user_email);

2) plugins/wpdiscuz-comment-author-info/includes/wcai-dbmanager.php
Replace the function getAuthorAllComments (line 16 to 25) to this: public function getAuthorAllComments($userId, $email = '') {
$result = '';
if (trim($email)) {
$sql = $this->db->prepare("SELECT `comment_ID`, `comment_approved` FROM {$this->db->comments} WHERE `comment_author_email` = %s", $email);
} else if (intval($userId)) {
$sql = $this->db->prepare("SELECT `comment_ID`, `comment_approved` FROM {$this->db->comments} WHERE `user_id` = %d", $userId);
}
$result = $this->db->get_results($sql);
return $result;
}

Hope that this help everyone that needs it. 

Topic Tags
1 Reply
Astghik
Posts: 3094
Admin
(@astghik)
Support Team
Joined: 2 years ago

Thank you @thepsir. I really appreciate you taking a time and share this information.

Share: