Search
Close
AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

Putting a text to the end of each comment

11 Posts
3 Users
1 Reactions
2,564 Views
(@mert2312)
Active Member
Joined: 6 years ago
Posts: 6
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
  [#5750]

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
Elvina
(@elvina)
Support
Joined: 7 years ago
Posts: 1403
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
 

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)
Active Member
Joined: 6 years ago
Posts: 6
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
 

@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)
Support
Joined: 7 years ago
Posts: 1403
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
 
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 reacted
ReplyQuote
(@mert2312)
Active Member
Joined: 6 years ago
Posts: 6
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
 

@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)
Support
Joined: 7 years ago
Posts: 1403
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
 

@mert2312,

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

 



   
ReplyQuote
(@mert2312)
Active Member
Joined: 6 years ago
Posts: 6
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
 

@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)
Active Member
Joined: 6 years ago
Posts: 6
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
 

@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
(@astgh)
Illustrious Member Admin
Joined: 8 years ago
Posts: 6645
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
 

@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)
Active Member
Joined: 6 years ago
Posts: 6
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
 

@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
(@astgh)
Illustrious Member Admin
Joined: 8 years ago
Posts: 6645
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
 

@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:
Scroll to top