Forums

[resolved] Capability type and capabilities (6 posts)

  1. Arru
    Member
    Posted 6 months ago #

    Hi everybody!

    I'm playing with my custom post types and got in trouble with it's capabilities.

    I created custom post type 'hints' which must have the same capabilities as post except that subscribers should also be able to add new content.

    So I created my custom post type with capability type 'post' and two new capabilities:

    'capability_type' => 'post',
    'capabilities' => array(
    			'delete_posts' => 'delete_hints',
    			'edit_posts' => 'edit_hints',
    			);

    And later assigned those new capabilities to subscriber and admin:

    function add_ego_caps() {
    $role = get_role( 'subscriber' );
    $role->add_cap( 'edit_hints' );
    $role->add_cap( 'delete_hints' );
    
    $role2 = get_role( 'administrator' );
    $role2->add_cap( 'delete_hints' );
    $role2->add_cap( 'edit_hints' );
    
    }

    But noone can add-edit-delete hints. Both user-types can get to the editor write text for their new hint but clicking the button "publish" takes to page wich says: "You have no right to change this post"

    Also are missing admins links to edit or delete posts.

    Any ideas? Could this be bug?

  2. keesiemeijer
    moderator
    Posted 6 months ago #

  3. Arru
    Member
    Posted 6 months ago #

    Thanks keesiemeijer,
    it is helpful article and I'll dig into it.

    If I get it right then my whole conception to have default capability type "post" with two exceptional capabilities is wrong and I must define new capability type from the very beginning...?

  4. keesiemeijer
    moderator
    Posted 6 months ago #

  5. Arru
    Member
    Posted 6 months ago #

    Done, thanks to the article you pointed out, and first tests show it to be working perfectly!

    I could use "posts" capabilities. Just needed to define three meta capabilities for my custom post type. And to map them.

    Thanks again!

  6. keesiemeijer
    moderator
    Posted 6 months ago #

    You're welcome. Glad you got it resolved

Reply

You must log in to post.

About this Topic