• Hello!

    I am into a new project that needs a custom post type and a new user role.
    These new users will have some cpt posts assign to them by the admins

    Two things need there
    1) the users must see only their cpt posts
    2) users must be able too view their posts but not to edit them or create new

    so here are the capabilities in ctp args

    
    'capabilities' => array(
    	'publish_posts' => 'publish_cpts',
    	'edit_posts' => 'edit_cpts',
    	'edit_others_posts' => 'edit_others_cpts',
    	'delete_posts' => 'delete_cpts',
    	'delete_others_posts' => 'delete_others_cpts',
    	'read_private_posts' => 'read_private_cpts',
    	'edit_post' => 'edit_cpt',
    	'delete_post' => 'delete_cpt',
    	'read_post' => 'read_cpt'
    )
    

    so with these caps at ctp, i assigned to the new user role
    1) read (default cap so user can view wp-admin)
    2) read_cpt

    problems:
    1) to be able the user to view the cpt posts, the “edit_cpts” must be assigned for some reason that i do not understand… the read_cpt will not work
    2) if the “edit_cpts” is assigned then the user is able to see the others users posts

    can someone explain me if these caps are working that way or i did not get something right

    ps i would prefer not using a pre_post hook to get the result i want to…

    Thnaks

Viewing 1 replies (of 1 total)
  • Defining the capabilities parameter on the CPT doesn’t do much. If you need something different from the standard, you have to write a filter for map_meta_cap and clearly define your user roles to have these capabilities.

    Pick any working plugin that has CPT and custom roles, and read the code. A good example is bbpress, since you know how a forum works. The plugin defines three CPTs (forums, topics, replies) and then 5 different user roles (keymaster, moderator, participant, blocked, spectator) and all of this works independently from the standard Post and Page and standard roles (but it does mesh multiple roles for a user).
    See https://plugins.trac.www.ads-software.com/browser/bbpress/trunk/includes/core/capabilities.php

Viewing 1 replies (of 1 total)
  • The topic ‘CPT capabilities not working as expected’ is closed to new replies.