Capability to EDIT but not ADD Custom Post Type

EDIT: this is not a plugin issue, sorry, please move it in a more general room

Hi all,
i'm quite new here at WPMUDEV so I don't know if it's not polite to ask things not strictly related to your plugins or themes. But I'm having this issue for so long that I really need to discuss with someone that has more confidence with WP.

General Matter: Capabilities for Custom Post Types

Question 1
How to create a custom post type and let users edit the only one (created by admin or script) of which they are the author. But (and this is where I get stuck) avoid them to Add New one with a capability (not via admin css functions).

Question 2
How to add edit_published_custom-post-type capability.
This is my steps, but no sign of edit_published_stuff. I hope someone can help me finding where i'm wrong

1) I create a Custom post type like this one:

function professionisti() {
$labels = array(
'name' => 'Professionisti',
'singular_name' => 'Professionista',
'add_new' =>  'Aggiungi Nuovo',
'add_new_item' => 'Aggiungi Nuovo Professionista',
'edit_item' => 'Modifica Professionista',
'new_item' => 'Nuovo Professionista',
'view_item' => 'Vedi Professionista',
'search_items' => 'Cerca Professionista',
'not_found' => 'Nessun Professionista Trovato',
'not_found_in_trash' => 'Nessun Professionista trovato nel Cestino',
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'menu_position' => 3,
'menu_icon' => get_bloginfo('stylesheet_directory').'/images/author.png',
'capability_type' => array('professionista', 'professionisti'),
'map_meta_cap' => true,
'capabilities' => array(
				'publish_posts' => 'publish_professionisti',
				'edit_posts' => 'edit_professionisti',
				'edit_others_posts' => 'edit_others_professionisti',
				'edit_published_posts' => 'edit_published_professionisti',
				'delete_posts' => 'delete_professionisti',
				'delete_others_posts' => 'delete_others_professionisti',
				'read_private_posts' => 'read_private_professionisti',
				'edit_post' => 'edit_professionista',
				'delete_post' => 'delete_professionista',
				'read_post' => 'read_professionista',
			),
'hierarchical' => false,
'rewrite'         => array(
					'slug'		 	=> 'psicologo',
					'with_front'	=> false
				),
'_builtin' => false,
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author', 'page-attributes'));
register_post_type( 'professionisti' , $args );

As you can see, in the capabilities array I write down this line:
'edit_published_posts' => 'edit_published_professionisti',

2) then I use User Role Editor Plugin (http://wordpress.org/extend/plugins/user-role-editor/) to assign capabilities to different roles.

3) But wait, why all "professionisti" capabilities are there EXCEPT "edit_published_professionisti"?

4) and why if I add a plugin like Revisionary (meant to let users modify their post and post type) and I check an option saying "Include capabilities for all custom post types in the WordPress Revisor role" (yes it adds even a role) another odd capability appair: "delete_professionistis" (with the final 's', you can look at this screenshot: http://dl.dropbox.com/u/3261727/ruoli.venessere.png )

there MUST be something i did not undestand q__q

  • DavidM
    • DEV MAN’s Mascot

    Hi bluantinoo and welcome to WPMU DEV!

    I've gone ahead and moved this to the Advanced WordPress forum for ya!

    Your question number one seems to be addressed by the edit_others_posts capability, have you looked into that one?

    As for your second question, I'm not aware of something like edit_published_posts for custom post types myself. I'll ask a couple of the guys over here if they know of anything like that.

    As for the other items you mentioned, perhaps we could focus on the initial questions you mentioned first off.

    Also, Justin Tadlock's article at the following provides some great coverage of these things. If you haven't read that already, perhaps that'll help some?
    http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress

    Thanks,
    David

  • bluantinoo
    • WPMU DEV Initiate

    Hi David,
    thank for replying, I'd like to continue this discussion, I think a lot of people are confused about custom post type capabilities, so maybe this is not just for me!

    Question N1 I think it's sadly solved: the issue is, as you say, related to "edit_others_posts" capabiilty. Surely i'm not giving users this capability. Instead I would like to let them edit their published custom post type, but NOT ADD.
    But i've come to sad conclusion that it is not possibile with actual WP capabilities system.
    If I'm not wrong, to give access to any post type in admin interface you have to give the edit_posts capability. And this cap integrates the function of adding posts. So... Maybe the only way is really just hiding add new buttons and do not give the pubblish_posts cap. So even if they reach the add new page writing down the URL on browser they will be able to add a post, but it will be not pubblished.

    Question N2, after further studying, I think you're right. the "edit_others_posts" does not exist for custom post types... But like this I get confused: if giving users the "edit_posts" already give edit access only to the posts of CPT they are authors, and to let them edit others posts you have to give the "edit_others_posts" cap, how can I manage to let them edit the published posts (custom post type) they are authors (without using Revisionary plugin)?

    Issue N3: the final "s". Here I'm really blind. I cannot find anywhere discussions or articles about this (not even in awesome Tadlock's posts that I know by heart).
    Why if I use any plugin that manages capabilities for my custom post types I always see it adding some other capabiity with a final "s" caracter.
    The example code I pasted above is evidently not sufficient to define the "Professionisti" custom post type caps, if a nice plugin as Revisionary when activated creates the "delete_professionistis" (notice the final 's') even if I've already defined the "delete_professionisti" (without the 's') in my code.
    What is that final s?

  • bluantinoo
    • WPMU DEV Initiate

    Hi masonjames,
    actually i know Members (and others like that: user role editor, capability manager, map cap, etc...)
    but as I said, for wordpress the edit_posts capability gives access to that post interface in admin, and in the same time gives access to the ability to add posts.

    So, the only ways to "hide" the add new buttons is the ones I did not like:
    - to hide it from admin menu you can filter the menu array
    - to hide it from admin edit.php page you need to apply some css
    best resource I've found for this is this one: http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link

    Doing that you do not revoke the capabiilty to add new posts, you just hide buttons. If a user manipulates the URL he will be capable to add a new post.
    But as you can revoke publish_posts capability this is not a severe issue, because even if users add posts they won't display on public site.
    In my opinion, even if it works, it's more like a workaround than a solution. But there are no alternatives right now.

    One more tip I want to share: I've found a way even to let users edit their own posts, but do not let them publish their edits without an editor moderation. This via the excellent "Revisionary" plugin: http://wordpress.org/extend/plugins/revisionary/

    --------

    For the final "s" question, I finally found that too.

    In register_post_type function, you have the possibility to define a precise "key" used by WP to construct that post type capabilities.

    You can do like that:

    'capability_type' => 'myposttype',

    Or you can specify an array of 2 keys: singular and plural

    'capability_type' => array('myposttype', 'myposttypes'),

    Then you have to define and assign to at least a role that capabilities, otherwise they will simply not exist.

    A question of language.
    If you do not define capabilities on code, but with the use of some plugins (like revisionary, map cap, role scoper, and so on) that detects custom post types and creates automatically the capabilities,
    it would use the string you pass 'capability_type' => 'myposttype', to construct them.

    Well, most plugins assumes that you are talking english, so they just keep the string 'myposttype' and add an 's' to construct primitive capabilities (edit_myposttypes).

    But if your language is not english, you have to define both singular and plural to be sure that all plugins uses the correct form of plural.

    The example code I've posted opening this thread is good to give an example:
    'capability_type' => array('professionista', 'professionisti'),

    any plugin will create the edit_professionisti capability, and not edit_professionistas (that's terrible Italian:slight_smile:

    -----

    So in the end, thank you guys for supporting me, and forgive if I felt the right to write so much in this post. But I'm sure there are a lot of people wandering on the web trying to figure out stuff like this.

  • Mason
    • DEV MAN’s Sidekick

    Hiya,

    as I said, for wordpress the edit_posts capability gives access to that post interface in admin, and in the same time gives access to the ability to add posts.

    Ahh, yeah. That's what I get for speed reading. You're correct of course.

    hide it from admin edit.php page you need to apply some css

    Yep. That's what I'd recommend.

    Interesting point about the language issue with post type plurals. Because they're custom post types, the plugin's can't really predict what a plural will look like - the same would happen with certain English words as well...

    My only thought there would be to use our Custom Admin Text plugin to simply replace the words:
    https://premium.wpmudev.org/project/site-wide-text-change

    That'll allow you full control over what is displayed and fix the errors (though it's obviously a work- around and not full solution).

    Anyway, thanks for all the information. I'm sure this will help future members :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.