Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 7th Mar 2023, 11:29 AM   #1
New Warrior Member
Registered Member
 
cybercli's Avatar
 
Join Date: 2012
Location: Houston, TX
Posts: 22
Thanks: 2
Thanked 1 Time in 1 Post
Default
Enable post comments in WordPress based on author role
Share on: 
fb share twitter share gplus share more share

I have a custom post type "public notice" whereby subscribers and paid members can create posts of that post type. However, I want to enable the comments section on posts created by paid members with the user role of "member" and disable it on posts created by free subscribers with the role of "subscriber". Is this possible?

Thanks

Independent Funding Agent & Investment Consultant
GoodLife Financial

Destiny is a matter of choice, not a matter of chance. ~ W. Churchill
cybercli is offline  
Unread 9th Mar 2023, 07:24 AM   #2
New Warrior Member
 
Join Date: 2022
Location: Mohali, Punjab, India
Posts: 16
Thanks: 0
Thanked 5 Times in 5 Posts
Default
RE: Enable post comments in WordPress based on author role
Share on: 
fb share twitter share gplus share more share

By default, WordPress allows users with the "Editor" and "Administrator" roles to post comments on your website. Nevertheless, you can use a plugin like "User Role Editor" or custom code to accomplish this if you want to allow users with other roles to post comments as well.
garybehl is offline  
Unread 19th Jun 2023, 11:38 AM   #3
cyberseo.net
War Room Member
 
CyberSEO's Avatar
 
Join Date: 2011
Location: Over 100K websites
Posts: 769
Thanks: 24
Thanked 123 Times in 99 Posts
Default
Re: Enable post comments in WordPress based on author role
Share on: 
fb share twitter share gplus share more share

Yes, this is possible with WordPress, but it will require some custom coding to get it done. You can add custom code to your theme's functions.php file, or better yet, create a simple custom plugin to handle this task. Here's a simple example of how to do this:


function cybercli_comments_open($open, $post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
if ($post->post_type == 'public_notice') {
if (in_array('subscriber', $author->roles)) {
$open = false;
} elseif (in_array('member', $author->roles)) {
$open = true;
}
}
return $open;
}
add_filter('comments_open', 'cybercli_comments_open', 10, 2);


P.S. I've tried to post the code as PHP block, but for some reason this board strips off all the variables in this case...

CyberSEO Pro - the ultimate AI autoblogging and RSS, XML, HTML, JSON, CSV, XLS import plugin for WordPress with support for all existing LLMs and image generating AI models.
CyberSEO is offline  
The Following User Says Thank You to CyberSEO For This Useful Post:
Closed Thread


Bookmarks

Tags
author, based, comments, enable, post, role, wordpress


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:07 PM.