| | #1 |
| New Warrior Member Registered Member Join Date: 2012 Location: Houston, TX
Posts: 22
Thanks: 2
Thanked 1 Time in 1 Post
|
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 | |
| |
| | #2 |
| New Warrior Member Join Date: 2022 Location: Mohali, Punjab, India
Posts: 16
Thanks: 0
Thanked 5 Times in 5 Posts
|
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.
|
| |
| | #3 |
| cyberseo.net War Room Member Join Date: 2011 Location: Over 100K websites
Posts: 769
Thanks: 24
Thanked 123 Times in 99 Posts
|
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.
| |
| |
| The Following User Says Thank You to CyberSEO For This Useful Post: |
|
| Bookmarks |
| Tags |
| author, based, comments, enable, post, role, wordpress |
| |