The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
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
how to display some...
 
Notifications
Clear all

Question [Solved] how to display some phrases when comment section is hidden.

7 Posts
2 Users
1 Reactions
1,477 Views
Posts: 5
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
(@lightlaw)
Active Member
Joined: 2 years ago
[#7887]

I've set Comment Form Settings to hide comment section for user roles, and it works fine.

But, I want to display something like below in that hidden section :

"You are not allowed to see the comments."

How can I do it?

 

Topic Tags
6 Replies
Asti
Posts: 8228
 Asti
Support
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
(@asti)
Illustrious Member
Joined: 8 years ago

Hi,

You can use the wpdiscuz_before_comments hook and display messsage. Just check if the current user has permission to view comments.  


Posts: 5
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
(@lightlaw)
Active Member
Joined: 2 years ago

Thank you Asti.

Where should I insert the wpdiscuz_before_comments hook?

Please understand that I am a beginner in coding.


4 Replies
Asti
 Asti
Support
(@asti)
Joined: 8 years ago

Illustrious Member
Posts: 8228
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

@lightlaw,

In your currently active theme functions.php file. 


(@lightlaw)
Joined: 2 years ago

Active Member
Posts: 5
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

@asti Thanks, but custom messages are displayed not only to unpermitted users, but also to permitted users. I want to display custom messages only to unpermitted users.


Asti
 Asti
Support
(@asti)
Joined: 8 years ago

Illustrious Member
Posts: 8228
Asti
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

@lightlaw,

Just check if the current user has permission to view comments.

The provided code is just an example. You should customize it to suit your needs and ensure it functions as desired.


(@lightlaw)
Joined: 2 years ago

Active Member
Posts: 5
Asti
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

@asti Thank you. I solved it by adding the following code.

 

add_action("wpdiscuz_before_comments", function ($post, $currentUser, $commentsCount) {
   
    $user = wp_get_current_user();
    $user_roles = $user->roles;
 
 
    if (in_array(‘role01', $user_roles) || in_array(‘role02', $user_roles)) {
        echo "Custom Message";
    }
}, 10, 3);