Here’s what I ended up with. For limited access users, I set comments on when the post guid is empty. Otherwise, I completely remove the comment_status field for those users. That defaults new posts to comments enabled, prevents limited access user edits from switching them off, while allowing admins to override the setting on/off.
add_filter( 'wp_insert_post_data', 'handle_comments_setting' );
function handle_comments_setting( $data ) {
if ( current_user_can( 'limited_role_name' )) {
if ( $data['guid'] == '') {
//Default new posts to allow comments
$data['comment_status'] = "open";
} else {
//Otherwise ignore comment setting for community_member role users
unset($data['comment_status']);
}
}
return $data;
}
Related Posts:
- How to prevent a post from being deleted?
- Limit access to posts/pages by user roles
- How Do I Use The WordPress Plugin Posts 2 Posts by Scribu?
- Custom Post Type causes Page Not Found
- Is there a way to order posts and custom post types as one group?
- Accessing post’s meta data based on user’s click of a post
- get_post_type on post.php
- Matching Chapters to a Custom posts [closed]
- Custom post type – no layout section of Document tab, and no author choice
- How to allow an editor to edit all WordPress blog posts but have the last say as administrator?
- Redirect to another page using contact form 7? [closed]
- How to delete all trashed item in one-go
- Custom setup of wordpress comments that are displayed
- posts from multiple post types in one slider
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Custom Template for wordpress cpt plugin
- What hook can I use to modify custom post data before it is displayed on the page?
- Creating teams of users in WordPress
- Is it possible to pin a post in second position from top
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Adding custom post category to categories widget
- How to display the custom post related blog by category?
- WordPress hide post from custom post-type on a single page
- Is it possible to customize a wordpress post from outside dashboard(Something like site.com/post-type/post/?e=post_id)?
- Different email notifications (about pending posts) to different users
- Hide some portion on single.php base on author
- WordPress list child pages of custom post type
- Insert data in custom table during new post creation
- How to export post tags from wordpress
- Redesigning Custom Post Type “Add New” page
- Getting Custom Post Type content from main-site of a Multisite
- Custom comment type maybe?
- Twillio How To Send SMS for Custom Post Type
- Publish Post After Click On A Link
- Remove Adminstrator Hyperlink from a user having role to add and see users
- Restrict backend but allow to use post.php?action=delete&post=POSTID from front-end
- Edit/revise option for authors to suggest improvement to posts [closed]
- How to Build a Movie Library in WordPress 3.x
- How do I get multiple pages by title?
- How can I change plugin to give access to editor user role?
- I need to add a custom “cover” to every new post — plugin or custom setup?
- Action on post publish
- [Plugin: Posts 2 Posts] How does it work?
- How to add new tabs in post.php
- Allow users mark posts as “complete”?
- Using the “Latest posts” feature on a different site
- How can i list random post from multiple category?
- dynamically generating plugin syntax
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- Hook to plugins admin settings
- Exclude post by custom meta with pre_get_posts
- get_post_type() and WP_QUERY issue
- Is there an easy way to flag posts in the admin area?
- finding whether request is for post, and post id
- Filter custom posts based on the user role of author
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Trying to fix form resubmition with PRG (Getting error: Cannot modify header information – headers already sent by)
- Display wordpress post’s in popup?
- Unable to add TAB character to post?
- Can I allow certain people to add/edit pages within a parent?
- can i limit editing specific custom fields to certain roles?
- WordPress custom taxonomy not showing
- Using ACF default value to autoincrement a number field
- Is there a way to make the main page only display a brief description of the full article?
- How to Resize the Custom Post Images?
- How to display the featured post on the category page?
- Show WordPress Plugin Menu(Admin) To Editor
- Use jQuery Datepicker code from plugin
- Posts 2 Posts: Display custom types connected to the same other custom type but with another connection
- How to get Recent Post From Each Category with Thumbnail?
- Why the internal link get converted into a comment?
- Import Recent Posts Only and Ignore old ones if exist
- WordPress REST API: Query media files attached to a custom post type
- How to get the custom field value using SQL query
- Copy/paste local images not working in WordPress
- How to change my 3000 Published post status to Draft using PHPMyAdmin
- How to display the category name in the tab and post inside the tab in WordPress?
- Want to build parent-child relationships between custom post types created with CPT UI
- Add an action based on custom post meta field
- Ultimate Members Default Post Layout problem
- how to create user profile pages and display them based on users roles
- Public WP website with one area just for members
- All Post WordPress Page Error
- Is it possible to create duplicate post on other site (either push, on publish, or pull, periodically)?
- Add dynamic color to each category item
- Is there any hook to change media html in post? [duplicate]
- Publish Post but don’t call publish hook in foreground post creation
- get post excerpt by query
- Making a Custom Post Type Publish Loop
- WordPress User Frontend Editing Custom Fields
- Want to add post to user dashboard
- Allow a role to edit one specific plugin
- WordPress Role Capability Restriction
- Make a magic tag work with Custom Post Types
- Sync roles across several plugins
- Shortcode returning specific content of a post
- How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
- Set the title of a custom post automatically by using info from custom fields?
- public custom posts not showing in my wordpress plugin
- plugin translation *.mo file not getting loaded for custom post