The effects of alcohol on
sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Enable comment form for author and user-role
How-to and Troubleshooting
(@3dwan)
Eminent Member
Joined: 6 years ago
Hello,
Is there a snippet to allow only vendor role and author of the post to view the comment form and restrict other visitors and guests from reading the comments?
(@asti)
Illustrious Member
Joined: 8 years ago
Hi @3dwan,
you can use the following two options:
In this case, the comments will be visible for the roles, however, they'll not be able to post a comment.
The whole comment section can be hidden for the guests by the following CSS code:
body:not(.logged-in) #comments #wpdcom {
display: none !important;
}
(@3dwan)
Eminent Member
Joined: 6 years ago
Thank you for the fast reply, I will add the css code to hide comments from guests, but how do I hide them from other user roles? I have already defined the settings you mentioned but I want comments to be only visible to the author of the post and user-role because comments will act as agreement on services and I don't want the author name to be visible to subscriber user role
(@asti)
Joined: 8 years ago
Illustrious Member
Posts: 8191
Jul 29, 2020 10:05 am
@3dwan,
Below is provided an example:
$user = wp_get_current_user();
if ( in_array( 'subscriber', (array) $user->roles ) ) {
comments_template();
}
In this example, the comment section is disabled for the subscriber user role.
The code should be added in the active theme functions.php file.
(@3dwan)
Eminent Member
Joined: 6 years ago
Hello,
I have tried the above snippet and it doesn't work, sorry im not a developer I don't know coding but the above doesn't work.
I am worried if it works it will also disable reviews for products. I need to hide comments for user role on posts only not products.
Thank you a lot on advance
(@asti)
Joined: 8 years ago
Illustrious Member
Posts: 8191
Aug 01, 2020 9:54 am
@3dwan,
sorry for the late response.
The code provided by me in this post should be added in the template files of the theme, not in the functions.php file.
For example, in the single.php file, you'll need to find the comments_template(); function and replace it with the code I've provided.
(@3dwan)
Eminent Member
Joined: 6 years ago
Hello,
Thank you for your reply, if I provided you with the admin access, could you apply the snippet?
Because I have tried to search for comment_template but I couldn't find it.
Waiting for your reply, thank you in advance
(@asti)
Joined: 8 years ago
Illustrious Member
Posts: 8191
Aug 07, 2020 8:22 am
@3dwan,
if I provided you with the admin access, could you apply the snippet?
sure, please send it to info[at]gvectors.com email address.
Please don't forget to leave the email subject here to allow us to easily find it.
(@asti)
Joined: 8 years ago
Illustrious Member
Posts: 8191
Aug 10, 2020 1:14 pm
Hi @3dwan,
The changes were implemented by our developers. Please check it.
(@3dwan)
Joined: 6 years ago
Eminent Member
Posts: 17
Aug 10, 2020 2:28 pm
@asti hello,
I have checked the changes, and nothing changed. All users can view and see comments instead of limiting access to author and vendor
(@3dwan)
Joined: 6 years ago
Eminent Member
Posts: 17
Aug 10, 2020 4:41 pm
@asti
the comment form doesn't appear for other user roles, but any user who posted an article and has author role, can see comments for all articles, he should be able to see comments for articles he wrote only. and users with role vendor can see comments in all articles. Please help me fix this, as we are very close to solving this issue. also please guide me on which file did you implement the snippet for future reference.
Thank you very very much in advance
(@asti)
Joined: 8 years ago
Illustrious Member
Posts: 8191
Aug 11, 2020 1:02 pm
@3dwan,
Please help me fix this, as we are very close to solving this issue. also please guide me on which file did you implement the snippet for future reference.
We're really sorry, but there is no easy solution we can provide you. You should ask some developer to do this custom work for you.
(@3dwan)
Joined: 6 years ago
Eminent Member
Posts: 17
Aug 11, 2020 1:17 pm
@asti
Np but can you tell me where were the changes made? In which file?
(@asti)
Joined: 8 years ago
Illustrious Member
Posts: 8191
Aug 12, 2020 9:07 am
@3dwan,
There is no only one place where you should make the changes. The changes should be included in several files.
(@3dwan)
Eminent Member
Joined: 6 years ago
Hi @3dwan,
The changes were implemented by our developers. Please check it.
I mean these changes, where can I find them?
(@asti)
Joined: 8 years ago
Illustrious Member
Posts: 8191
Aug 14, 2020 9:55 am
@3dwan,
In almost all files in the inc/post_layout folder in the active theme.
There were added the following code:
$user = wp_get_current_user();
if ( !in_array( 'subscriber', (array) $user->roles ) ) {
comments_template();
}