The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Enable comment form...
 
Share:
Notifications
Clear all

Enable comment form for author and user-role

16 Posts
2 Users
0 Reactions
1,153 Views
Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 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?

15 Replies
Asti
Posts: 7617
 Asti
Support
(@asti)
Illustrious Member
Joined: 7 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
Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 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

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

Illustrious Member
Posts: 7617

@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
Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 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 

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

Illustrious Member
Posts: 7617

@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
Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 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 

Reply
7 Replies
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

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

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

Hi @3dwan,

The changes were implemented by our developers. Please check it. 

Reply
(@3dwan)
Joined: 4 years ago

Eminent Member
Posts: 17

@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

Reply
(@3dwan)
Joined: 4 years ago

Eminent Member
Posts: 17

@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

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

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

Reply
(@3dwan)
Joined: 4 years ago

Eminent Member
Posts: 17

@asti

Np but can you tell me where were the changes made? In which file?

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@3dwan,

There is no only one place where you should make the changes. The changes should be included in several files. 

Reply
Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 years ago
Posted by: @asti

Hi @3dwan,

The changes were implemented by our developers. Please check it. 

I mean these changes, where can I find them?

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

Illustrious Member
Posts: 7617

@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();
}

 

Reply
Share: