Change WordPress user roles and capabilities Forums How to or FAQ Limit Access to custom post types

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #4454
    Alistair
    Spectator

    Is there a way to limit access to custom post types per role?

    It seems to be all or nothing, just wondering if you can control the access per user role

    #4455
    Vladimir
    Keymaster

    If custom post types use the same capability type ‘post’, ‘Yes’, role may have access to all CPT with ‘edit_posts’ or to none of them.
    But if every CPT uses own unique capability type then videos will be protected by ‘edit_videos’, ‘books’ – by ‘edit_books’, etc. You can grant access to the selected CPT at the role level in this case.
    If you define CPT yourself via PHP or plugin, like “Custom Post Types User Interface” then use unique capability type for this purpose.
    If CPT is defined by external source (theme or plugin) you can use “Force custom post types to use their own capabilities” option at “Settings->User Role Editor->Additional Modules” tab. Take into account that this option is applied to all existing custom post types, including WordPress built-in ‘attachments’. Correspondent roles modification would be required.

    #4569
    scsedel
    Participant

    I have a similar issue and I think any post or custom post use the same capabilities.
    Anyway, if I give custom post capabilities (create, edit, delete) to the new role, in my backend I can only see Post Menu on the left but not of any custom ones.

    I created a user for you in my backend, I can give you access in private.

    Thank you

    #4570
    Vladimir
    Keymaster

    You can send URL and admin credentials to support [at-sign] role-editor.com
    To what custom post type do you wish to provide access and to what role?

    #4571
    Vladimir
    Keymaster

    Developer who added custom post types at your site registered theme with user capabilities default for the WordPress built-in posts, but protected admin menu items by ‘edit_pages’ capability.
    I used “Admin menu access” add-on to get this information: https://www.role-editor.com/block-admin-menu-items

    Then I added ‘edit_pages’ capability to the ‘Speaker’ role and blocked unneded menu items with the same “Admin menu” button.

    Tests showed that while custom post types are defined with default ‘post’ capability type, they require really capabilities from the ‘pages’ group. So I added them to the ‘Speaker” role.

    #6569
    thebigbanik
    Participant

    Hi Vladimir, I use the CPT UI plugin to create 3 custom post types BLOG, PROGRAMS and PERSONEL. In each custom post I have set accordingly “blog”, “programs” and “personel” as Capability type. Then in user role editor I have created capabilities for each type (create_blog, edit_blog, read_blog, delete_blog, publish_blog) and so on for programs and personel. If a user role has all this new types enabled he can see only the blog CPT in the admin menu. The other 2 capabilities seams to not work dispite that I have already enable them. BUT, if in the CPT UI “PROGRAMS”, I change the Capability type to “blog” then the user can see the PROGRAMS in the admin menu. I am not sure if there is something else that I have to set. (Of course “Force custom post types to use their own capabilities” is enabled from the beggining). Thank you for your time in advanced.

    #6570
    Vladimir
    Keymaster

    Hi @thebigbanik,

    URE’s “Force custom post types to use their own capabilities’ works only for CPT, which has capability type ‘post’ – default for WordPress.

    If you set other capability type for CPT you really should create capabilities list yourself, but look how WordPress does that for capability type ‘post’:
    create_posts, edit_posts, delete_posts, publish_posts, edit_publish_posts, edit_others_posts.

    So you have to add not edit_blog, but edit_blogs, etc. Add ‘s’ to the end, if did not insert special multiple form at the CPU UI plugin.

    #6619
    whyknott
    Participant

    I have CPT UI installed and ACF plugin along with User Role Editor Pro. I created a new Custom Post Type called RENTALS and created a user role based on a duplicated role already created so I wouldn’t have to remember all the URE settings, except the new user role isn’t showing the featured image for the user. I’m an admin and I can visit RENTALS click on a listing and see the “Set Featured Image” tab in the document settings on the right column of the Gutenburg WP layout. Can you tell me what I need to do in order to get the Set Featured Image to work on a URE defined User?

    #6620
    Vladimir
    Keymaster

    Is ‘upload_files’ capability granted to a role?

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.