AI Assistant
Notifications
Clear all

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

2 Posts
2 Users
1 Reactions
2,437 Views
Posts: 1
Customer
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@thepsir)
Member
Joined: 7 years ago
[#3741]

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: 6645
Admin
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@astgh)
Illustrious Member
Joined: 8 years ago

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


Share:
Scroll to top