Notifications
Clear all

Paid Addons Support Forum Only

Please note, that here we only support Paid Addons issues and questions.

gVectors Support staff works from 6am to 6pm (GMT+0)

All questions related to wpForo and wpDiscuz free plugins should be asked in the corresponding plugin support forum:

 

wpDiscuz Support Forum   wpForo Support Forum

Putting a text to the end of each comment  

  RSS

mert2312
(@mert2312)
Active Member
Joined: 3 months ago
Posts: 6
18/04/2020 2:39 pm  

Hi. I'm looking for a action hook which helps me to put the length of comment in a text, for each comment posted. I also need to get access to the user id of the comment author. For example, after each comment posted, I want to put a text saying: The user id of the comment author is : x and the length of the comment is : y.

Any help would be appreciated.


Quote
Topic Tags
Elvina
(@elvina)
Noble Member Moderator
Joined: 10 months ago
Posts: 1177
18/04/2020 3:06 pm  

Hi @mert2312,

You should use the following hook to display the comment author name and the comment length message:

add_filter("comment_text", function ($content, $comment) {
$content .= "comment author is : " . $comment->user_id . " and the length of the comment is : " . strlen($comment->comment_content) . ".";
return $content;
}, 50, 2);

The hook should be added in the current active theme functions.php file.


ReplyQuote
mert2312
(@mert2312)
Active Member
Joined: 3 months ago
Posts: 6
18/04/2020 3:22 pm  

@elvina Real thanks for such a comprehensive and quick reply. There is only one more question: is that going to change the comment content on the database, or just what is shown on the screen? Thank you so much!


ReplyQuote
Elvina
(@elvina)
Noble Member Moderator
Joined: 10 months ago
Posts: 1177
18/04/2020 3:47 pm  
Posted by: @mert2312

is that going to change the comment content on the database, or just what is shown on the screen?

no, the comment content doesn't change in the database. It only displays the comment author name and the comment length message in the frontend.


mert2312 liked
ReplyQuote
mert2312
(@mert2312)
Active Member
Joined: 3 months ago
Posts: 6
18/04/2020 5:19 pm  

@elvina hello again, I was able to implement the code easily, thank your for that. But I had a problem afterwards: the button for "load more comments" is no longer working, it gets stuck. I think it uses AJAX but a problem occurs when I activate this code. How can I make both of them work?


ReplyQuote
Elvina
(@elvina)
Noble Member Moderator
Joined: 10 months ago
Posts: 1177
18/04/2020 5:26 pm  

@mert2312,

Please leave the example URL to allow us to check it.

 


ReplyQuote
mert2312
(@mert2312)
Active Member
Joined: 3 months ago
Posts: 6
18/04/2020 6:11 pm  

@elvina It's on multiple pages, but here's one of them: https://www.glonera.com/urun/diadermine-hydralist-nemlendirici-bakim-kremi-ipeksi-doku-50-ml/  

Thank you.


ReplyQuote
mert2312
(@mert2312)
Active Member
Joined: 3 months ago
Posts: 6
19/04/2020 10:52 pm  

@elvina hello again. I had to remove the code since it interferes on the comments section on the admin panel and causing some fatal errors afterwards. how can I make sure that the code is only shown on wpdiscuz comments section? Is there a hook specifically for this purpose?


ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 3 years ago
Posts: 4224
20/04/2020 1:26 pm  

@mert2312,

Please use the code below:

add_filter("comment_text", function ($content, $comment) {
if (!is_admin() || (is_admin() && wp_doing_ajax())) {
$content .= "comment author is : " . $comment->user_id . " and the length of the comment is : " . strlen($comment->comment_content) . ".";
}
return $content;
}, 50, 2);

ReplyQuote
mert2312
(@mert2312)
Active Member
Joined: 3 months ago
Posts: 6
20/04/2020 1:56 pm  

@astghik hello, thank for your reply. that worked for admin part and resolved the error issues, but ajax part is still not working. maybe the function wp_doing_ajax() should be replaced with something else or modified somehow, but I don't know how to deal with this. still a huge help, thanks for that.


ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 3 years ago
Posts: 4224
21/04/2020 2:13 pm  

@mert2312,

We see everything is working fine now. Please explain using some screenshots the issue you see. I'd also suggest you press CTRL + F5 (twice) on the frontend before checking. 


ReplyQuote
Share: