Share:
Notifications
Clear all

Enable comment form for author and user-role  


3dwan
Posts: 11
(@3dwan)
Active Member
Joined: 2 months 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?

6 Replies
Asti
Posts: 819
 Asti
Support
(@asti)
Support member
Joined: 3 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;
}
Reply
3dwan
Posts: 11
(@3dwan)
Active Member
Joined: 2 months 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

Reply
1 Reply
Asti
 Asti
Support
(@asti)
Joined: 3 years ago

Support member
Posts: 819

@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. 

Reply
3dwan
Posts: 11
(@3dwan)
Active Member
Joined: 2 months 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 

Reply
1 Reply
Asti
 Asti
Support
(@asti)
Joined: 3 years ago

Support member
Posts: 819

@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. 

Reply
3dwan
Posts: 11
(@3dwan)
Active Member
Joined: 2 months 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 

Reply
Share: