This may be obvious to someone other than myself. I think I remember reading somewhere that an "image" is indeed a form of "post".

  • I have a custom post type called "listing"
  • I have a custom WP role of "client"

When I'm logged in as the "client", and I launch the media popup, browse to an image, click "show" to open it up, and then click "edit image", I get a -1. Ie. nothing else displays but "-1".

I can fix this issue by assigning my custom role the capability of "edit_posts". Why is this? As soon as I do this, I'm plagued with another problem, the "client" user role now has access to posts, comments & tools, which I don't want.

Perhaps I haven't set up my custom post type correctly with the capabilities? How can I allow the "client" to edit the images but not have access to posts?

      $args = array(
    'label' => 'Listing',
    'description' => '',
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'map_meta_cap' => true,
    'capability_type' => 'listing',
    'capabilities' => array(
                    'edit_post' => 'edit_listing',
                    'read_post' => 'read_listing',
                    'delete_post' => 'delete_listing',
                    'edit_posts' => 'edit_listings',
                    'edit_others_posts' => 'edit_others_listings',
                    'publish_posts' => 'publish_listings',
                    'read_private_posts' => 'read_private_listings',
                    'delete_posts' => 'delete_listings',
                    'delete_private_posts' => 'delete_private_listings',
                    'delete_published_posts' => 'delete_published_listings',
                    'delete_others_posts' => 'delete_others_listings',
                    'edit_private_posts' => 'edit_private_listings',
                    'edit_published_posts' => 'edit_published_listings',
                ),
    'menu_position' => 5, 
    'hierarchical' => false,
    'has_archive' => false, 
    'rewrite' => array('slug' => 'listing'), 
    'query_var' => true,
    'supports' => array('title'),
    'labels' => $labels
  ); 
link|improve this question

70% accept rate
Here are the capabilities I'm assigning to my custom wordpress role in case anyone can spot something delete_listing delete_listings delete_published_listings edit_listing edit_listings edit_published_listings publish_listing publish_listings read read_listing upload_files And I seem to need the following also for editing & deleting the images. Thought these would be remapped to edit_listings and delete_listings edit_posts delete_posts – Andrew Jul 5 '11 at 1:54
I found the following post which I'm currently looking into. Seems to be a larger issue than I thought where edit_posts is required. Looks like there is a general problem when using custom post types + custom roles + taxonomies wordpress.org/support/topic/… – Andrew Jul 5 '11 at 4:18
feedback

1 Answer

up vote 0 down vote accepted

If I had to guess: because images are Attachments, and Attachments are a Post-Type. Thus, in order to edit an image, which is an attachment, which is a post, requires the edit_post capability.

EDIT

Don't you have your capability mapping array keys/values reversed?

e.g. you have 'edit_posts' => 'edit_listings'. Shouldn't it instead be 'edit_listings' => 'edit_posts'?

link|improve this answer
In my custom post type setup above I've remapped by edit_posts to edit_listings, and the custom wordpress role has "edit_listings" assigned to it. I thought this was the purpose of remapping them, perhaps I was wrong? – Andrew Jul 4 '11 at 15:00
See edit in updated answer. – Chip Bennett Jul 4 '11 at 15:08
Bennett I reversed them but it didn't seem to have any affect and I still need edit_posts in order to be able to edit the image. Still shows -1 without it. I originally followed Justin Tadlock's "setting up your custom post type" example below where he has the _posts on the left and the remapped capabilities on the right. justintadlock.com/archives/2010/07/10/… – Andrew Jul 5 '11 at 1:49
After some time working with custom post types, role and capabilities I believe I understand them a great deal more. You were right, an image is a post, therefore in order for a user to be able to edit an image they uploaded, they need edit_posts. For them to delete an image, they need delete_posts. Not sure why my edit_listings didn't correctly map to edit_posts in the first place however. – Andrew Sep 12 '11 at 23:46
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.