• Resolved richarduk

    (@richarduk)


    I have a custom post type and a role that deals with it. Unfortunately that role needs to have edit_posts capabilities before it can create (custom) posts.

    What have I done wrong?

    I’ve mapped the meta capabilities.

Viewing 9 replies - 16 through 24 (of 24 total)
  • Thread Starter richarduk

    (@richarduk)

    I’ve not been able to get this to work yet, unfortunately. I get the ‘Posts / Add New’ menu item still.

    For the custom post type review and the taxonomy other_books

    register_taxonomy(
    		'other_books',
    		array( 'post', 'page', 'review' ),
    		array(
    			'public' => true,
    			'show_ui' => true,
    			'show_tagcloud' => true,
    			'show_in_nav_menus' => true,
    			'hierarchical' => false,
    'capabilities' => array('assign_terms'=>'edit_reviews', 'manage_terms' => 'manage_other_bookss', 'edit_terms' => 'manage_other_bookss', 'delete_terms' => 'manage_other_bookss'),

    I’ve also tried that lastline without the extra s

    'capabilities' => array('assign_terms'=>'edit_reviews', 'manage_terms' => 'manage_other_books', 'edit_terms' => 'manage_other_books', 'delete_terms' => 'manage_other_books'),`

    and I’ve tried changing assign_terms too

    'capabilities' => array('assign_terms'=>'edit_other_bookss', 'manage_terms' => 'manage_other_bookss', 'edit_terms' => 'manage_other_bookss', 'delete_terms' => 'manage_other_bookss'),`

    Can you post your code that registers your post_type and your role? I see bits and pieces in the post but it would be easier to fix if you can give it to me all put together. I’ll modify it to make it work and send it back to you. What version of wordpress are you running? I see that you are unnecessarily mapping the capabilities for your post_type above so that may be the issue. You also forgot the capability argument that creates your new capabilities prefix. Plus the code above is not correct for calling register_post_type. Either way just send me the code for registering all three together and I will fix it. You can post it to pastebin.com or here if you want.

    Thread Starter richarduk

    (@richarduk)

    That’s a very generous offer.

    I’ve removed a lot of comments, so I hope I haven’t accidentally removed anything vital.

    I’m trying to make my code have as many options / be as comprehensive as possible – even if unnecessarily so – so that at a future date if I need to make changes I don’t have to waste time working out what to do.

    https://pastebin.com/QebpBpDv

    Ok not sure if I’m on the right track but I created the custom post type with a book category taxonomy and other books tags. The user doesnt require edit_posts. You were trying to use the built in taxonomy category which is assigned to posts so that wont work. Not sure if you had a reason for doing this. I also removed post_tag taxonomy from your custom post_type cause that is also assigned to posts. If you need another type of tagging then you just need to add another taxonomy like other_books.

    https://pastebin.com/5s8pFv48

    I set this up as a plugin on my site and it all works. Let me know if I’m close to what you were trying to do. I’m not sure if you still need the meta capabilities mapping because I’m not sure what you are doing with it. Make sure you remove the capabilities you have assigned to the reviewer role if you already have it set up so you can start over. you don’t need to copy the subscriber role because it just has read capabilities but I left that in there. You shouldn’t be assigning capabilities or creating a role on every page load either. You should only do it once. I removed some arguments to the register_post_type and register_taxonomy functions because they were redundant. There are still some redundant arguments in there but i left them. Generally if you don’t know what the setting does don’t set it or you could cause more problems. I restructured your calls to register_post_type and register_taxonomy to make them easier to read. Let me know how close this is to what you want.

    Thread Starter richarduk

    (@richarduk)

    That’s pretty darned good and it looks like it’s exactly what I was trying to do.

    However, I want to be able to allow or disallow Reviewers from adding categories. At the moment Reviewers can add Book Categories.

    The Mapping Meta Capabilities code is from here:
    https://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types#comment-232645

    Just remove the manage_book_category capability from the role and it wont be able to add book categories. If you mean that you want do it on a per user basis then you would need to do some trickery with some custom user meta.

    Thread Starter richarduk

    (@richarduk)

    Thank you very much, foomagoo ??

    No problem. Return the favor if you see someone else with a problem you can solve. Mark this topic as resolved so others can see there is a solution.

    Hey guys, I seem to be having the exact same issue although mine started off with my custom role being unable to edit their gallery images. If you clicked “Edit Image” on the gallery popup, it would just return a “-1” in the space where the image used to be.

    After digging around I enabled “edit_posts” on the custom role in question and I was finally able to edit the images. I then discovered suddenly the custom role had access to the posts sections and all that which I didn’t want, so turned edit_posts off again. Then I found out I couldn’t access my main custom post type page unless edit_posts was enabled. Which doesn’t make sense because I could still edit the post without it in the first place.

    Found this thread, used foomagoo’s code to test it out and noticed it works nicely without edit_posts.

    However try uploading some images from the media uploader and then trying to edit them. They are still returning the “-1” for me unless edit_posts is turned on again. Or maybe I’m still doing something wrong. Can you guys check your configurations? Thanks for this helpful thread, I thought I was going mad

    This was on WP 3.1.4 and also tried it today on WP 3.2

    Thanks

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘Custom post type only works when role has edit_posts capability’ is closed to new replies.