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
- Show the author only own types of publications. (JetEngine, Elementor)
- How to check if the post exists in any of the categories?
- Creating a default Custom Post Template that a Theme can override
- How to Add jQuery Infinite Scroll to My Custom Archive Page
- Jetpack plugin (ShareDaddy): Prevent share buttons showing on custom post types?
- publish_post hook isn’t working for scheduled posts
- Seriously stuck with some custom meta box/plugin stuff
- [Plugin: Posts 2 Posts] reciprocal connections
- post expire after x days
- Set attached to state
- Bulk Image Uploader to create new post from each image [closed]
- Display comments of users on single page
- wordpress reusable content blocks
- Post query – show posts from specified day and month and whole years
- Support for simultaneous editing
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- How to make a customize role and view a specific plugins base on that role?
- View Private Published Page with URL Code (no login required)
- Solutions to repost categories into multisite blogs?
- List taxonomy terms for post as checkboxes
- How to create user that has permission to create new sites on WordPress with multisite option enabled?
- Can a Plugin Override New User Default Role Type
- ACF: post query, hide duplicate values [closed]
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- Multisite – maximum number of users with specific role
- Problem of encoding characters (apostrophes) in my posts publications
- How to backup single post in wordpress [closed]
- How to change the post form from plugin?
- Allowing users to Sign-up > Login > Post articles that need approval
- Amazon.com intergration with WordPress?
- Adding custom meta boxes to specified custom post type
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
- Is there a plugin or a way in the wordpress that would let us have different versions of a post or page accessibe to users?
- download button for audio file in post [closed]
- Send post changes to set email addresses (not users or subscribers)
- Post deleted in trash [closed]
- How to relate 3 wordpress components with each other (Create database relationships)
- How can I store data from custom fields to custom tables?
- Custom post type change excerpt more and excerpt length
- Remove specific administrator’s capability
- Enable comments for post when comments meta box removed
- Order posts of a custom post type by the event date using FT Calendar Plugin
- hardcoded wp pages/plugins problems
- How display specific category post to specific users?
- Is there a way to make [Table Of Content] plugin while not using revision data?
- Need to edit author permissions | custom taxonomy
- Save log for imports in WordPress database – options-table, custom post type or other place?
- page duplication on wordpress that wont stop
- Error in Fetching Custom Post Type parent Category URL (slug)
- Hidden permalink different from displayed permalink
- Need help with Task assigning and rewarding as currency which withdrawable
- how to convert frontpage.php to dynamic page?
- How can I see $post object in frontend from functions.php?
- Allow members to create groups on my site
- Creating custom “player-objects”
- How to make this custom capability work? [duplicate]
- Restrict role to use a plugin
- How to force regenerate thumbnails in WordPress posts?
- Serialize $_POST global in wordpress
- Displaying image from a repeatable group
- CPT-onomies CPT_TAXONOMY->get_terms extremely slow with 6K posts
- How to use shortcode of any plugin to show it visually where i want?
- Custom User Role
- WordPress not updating post or disable plugin instead a white page appear
- What method should I use for a sidebar widget that reads latest posts?
- How to add character to content of post?
- Custom feed parameters / Template overriding
- Is a custom post type considred a plugin?
- Zigconnect Plugin: Allowing editors to remove connections
- How to get an error message if a form is empty (plugin: Post for site) [closed]