You can filter the_content
to make sure only people with the right cap can see it:
function filter_the_content( $content ) {
// Check post type is book
// and that the current user is not lite user
if (get_post_type() == 'book'
&& ! current_user_can( 'read_book' ) ) {
// return a message in place of the content
return 'Why do you want to see this book? You can\'t read!';
}
// otherwise, show content
return $content;
}
add_filter( 'the_content', 'filter_the_content' );
However!
This will only work for lite user, meaning that any other user (including admins) won’t be able to see it from the front end.
You will have to add the read_book
capability to other roles.
Hope that’s what you are looking for.
Related Posts:
- How to assign specific users the capability to edit specific pages / posts / custom post types
- Custom post type capabilities require “create_posts” to access the edit posts list page
- How can I remove “Add new” button on custom post type
- Allow member to have access to custom post type only. Permission to only edit their own posts
- Possible to hide Custom Post Type UI/Menu from specific User Roles?
- Custom post type role permissions won’t let me read
- Allowing custom role access to custom post type in back end
- Allow user to Edit Posts but not Add New?
- Defining capabilities for custom post type
- Confusion with adding meta capabilities to a role after registering a Custom Post Type with corresponding ‘capability_type’ parameter
- Can I make user role that can only access a certian content type?
- REST API: How can I restrict a custom post type to only be accessible by authenticated users?
- Create user role restricted to specific CPT
- How to set individual capabilities on a taxonomy? Or how to re-register an existing taxonomy?
- Add Capabilities to Custom Post Type after it has been created [duplicate]
- How to not allow custom roles to edit published custom post types?
- How to restrict specific post types from being read or added by specific user roles (eg. author)?
- How do I code access to the built-in UI of a CPT when it’s placed as submenu of another CPT that is protected by role?
- Prevent author role from editing all posts in custom post type?
- Allow Users Access to Custom Post Type Only
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- Custom Role can’t trash Custom Post Type
- Limit access to page depending on user level
- Role Capabilities: Add New Ones?
- Limit users by custom taxonomy and user roles
- Add custom capabilities to existing custom post type
- allow edit of custom post type but not regular posts?
- Allow Administrator role access to custom capabilities [duplicate]
- Why is my Custom Post Type not showing up after adding capabilities?
- Cannot attach media when capabilities added to custom post type
- current_user_can() return FALSE but debugging says TRUE
- Role capability delete multiple post type posts doesn’t work
- map_meta_cap woes
- Roles for Custom Post Types
- can’t see custom post content filtered under “mine” filter in admin panel
- Define new user capability for custom post types?
- Custom post types as sub menu pages and role capabilities issue
- How to set individual capability of post type in individual category
- Restrict Access to Posts based on Custom User and Post Meta Data
- Giving permission to anyone (non-users as well) with a password to edit a post, possible?
- WooCommerce Customer Role Delete Custom Post Type
- Disable user from updating certain posts
- “Submit for review” for updates on existing posts
- Access to CPT but not to ‘post’ post type
- Allow add new post access to custom post but not wp post for some role
- Create custom post with custom user rules
- Allow user to only access custom post type
- WordPress custom post type capabilities issue
- Building Forums with Custom Post Types
- Role capabilities issue
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- Select other roles as custom post authors
- How to handle this specific case of custom post type?
- Roles and Capabilities in Custom Post Types
- How to fix the Post Preview Button (CPT & map_meta_cap)
- Restrict Custom Post Type per role in Dashboard
- Restrict access to custom post type based on its taxonomy terms
- Why “Mine” is the default view when adding ‘capability_type’ in register_post_type
- How to only display all posts to a custom User Role?
- Remove plugin settings from post creation page for a user role
- Allowing custom role user to edit post assigned to them but don’t let them create new custom type post
- Multiple useres editing specified content
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- How do you make a custom post type invisible for subscribers
- Front End users account with lots of user Roles (not Woocommerce)
- Capibilities of CPT WordPress
- Capabilities and mapping required for a role to be able to edit other’s posts of a custom type, BUT only be able to edit their own blog posts
- Weird capabilities / roles behavior
- Prevent author role from editing others posts
- creating different edit screens for different roles
- Capability to read user’s own draft post of CPT
- Custom role, capabilities, and post type: preview button wrecks things
- Custom post type & role issues
- Read-Only custom post type
- Frontend delete CPT post with custom role user
- Allowing a CPT post to be edited by a single user role
- Capability to edit own post, but not create new one
- CPT, Custom User Role and problem with user manager
- Custom post type media upload error with custom user role
- Issue with permalinks for custom post type
- What would prevent a custom role from viewing posts (both standard and custom)?
- Front end Submit not posting to Custom Post type
- Display and Allow users to edit their own profiles
- Custom Post Type supports author
- Check in function on custom page
- Reservations as Post
- Custom role can’t create permalink
- empty dashboard for custom role
- Allowing logged in users to create custom posts
- How to add post of custom type to a category with custom type capabilities
- Restrict editing of a custom post type based on status and user capabilities
- create category upon saving post and save post in that category
- Custom Plugin w/ Custom Post Types – Custom Posts Are Showing at all Privilege Levels – Is this possible to adjust?
- Front end post or photo or both
- WordPress Roles
- Understanding capabilities parameter in register_post_type()
- Need some suggestions with Relationship fields and CPT/ACF
- How to allow subscribers to create post of a new custom post type
- Only allow users (that are not admins) to edit a specific post
- WordPress User Role Permissions For Custom Post Type