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)
- Disable All In One SEO plugin for custom post type
- How to check if the post exists in any of the categories?
- Collaborative post submission [closed]
- Keep user’s privileges on accessing contents in JSON response
- CKEditor: Uncaught TypeError: switchEditors.switchto is not a functiononclick
- custom taxonomy and custom post type url conflict
- New post notification plugin [closed]
- Is there plugin to show recent posts from one website in the widget area of another?
- Bulk Image Uploader to create new post from each image [closed]
- How use %like% in sql statement wordpress
- Display comments of users on single page
- Advanced Custom Fields/User Role Editor – how to hide ACF for certain users?
- wordpress reusable content blocks
- Override plugin with functions.php
- Get the url of the full sized attachment image using post ID?
- Adding Plugin-specific Fields with wp_insert_post()?
- How create a role with admin capability less 1 or 2?
- Adding Attachment Display Settings in custom media frame
- Set user ID at time of wp_create_user
- Should i delete the posts created by a plugin on uninstall?
- Output HTML only on individual post view
- Allow users mark posts as “complete”?
- Using the “Latest posts” feature on a different site
- Update User Role
- Post query – show posts from specified day and month and whole years
- Plugin to restrict access to pages in wp-admin
- Getting user roles in plugin files
- How to achieve certain page (url) accessible to certain users
- Execute a plugin only on post pages
- RW Meta Box ,Problem setting post title
- How can i list random post from multiple category?
- How does WP handle multiple matching rewrite rules?
- Support for simultaneous editing
- how do i remove posts from a WP_Query so the pagination is right?
- Saving Custom Post types and fields to a custom table
- dynamically generating plugin syntax
- How to write a plugin to add users to a mail list
- How to get 1 or 2 specific posts on top of my wordpress blog?
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- Portfolio + Blog: multisite or plugin?
- Building a store locator with google maps
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
- 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?
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- View Private Published Page with URL Code (no login required)
- Hook to plugins admin settings
- With W3 Total Cache when I publish a post it does not appear in the homepage. Only if i purge all cache [closed]
- Disable plugin per user role
- If post has custom field then display css-class
- The problem with WordPress Importer
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- Correct way to make meta box with more than one meta field secure
- I want to extend the current themes’ single.php to display the meta fields of my CPT
- Cron job not firing
- Plugin custom post type – Internal server Error
- Exclude post by custom meta with pre_get_posts
- Solutions to repost categories into multisite blogs?
- How can I create a custom shortcode that will return a custom post type by ID?
- How to enable qTranslate languages tabs in custom plugin page
- How do I “get the next 10 posts after post_id == x”?
- Hiding posts – WP Hide Post not working
- how to give a user a role?
- Is it possible to create Custom Post plug-in?
- get_post_type() and WP_QUERY issue
- submit posts by unregistered users in wordpress
- Calendar Solution: Handling upcoming Dates with Posts?
- Is there an easy way to flag posts in the admin area?
- List taxonomy terms for post as checkboxes