Notifications
Clear all

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

2 Posts
2 Users
1 Reactions
1,846 Views
Posts: 1
Customer
Topic starter
(@thepsir)
Member
Joined: 6 years 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. 

1 Reply
Astghik
Posts: 6193
Admin
(@astgh)
Illustrious Member
Joined: 7 years ago

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

Share:
Scroll to top