Skip Navigation

[Geschlossen] Feature Request: Include capability_type on type def

This support ticket is created vor 11 Jahre. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 5 Antworten, has 4 Stimmen.

Last updated by Matthew vor 10 Jahre, 8 Monate.

Author
Artikel
#3205

I wonder if you have plans to add the capability_type on the post type definition screen(?)

I rely on these capabilities to control edit/publish/delete access to my post types, so I had to "hack" your plug-in to get them in.

Only two files need to be altered:
custom-types-form.php (to display entry field and save to db)
in wpcf_admin_custom_types_form()
<blockquote cite="wpcf_admin_custom_types_form()">
...
$form['capability_type'] = array(
'#type' => 'textfield',
'#name' => 'ct[capability_type]',
'#title' => __('Capability Type', 'wpcf'),
'#description' => __('Capability +root+. New capabilities will be generated by register_post_type() with +root+ in place of +post+.',
'wpcf'),
'#value' => isset($ct['capability_type']) ? $ct['capability_type'] : '',
'#inline' => true,
);
...

and
custom-types.php (to include it on the default properties of a type)

add an array element to the array returned by wpcf_custom_types_default() like so:
<blockquote cite="wpcf_custom_types_default()">
'public' => true,
'capability_type' => 'post',
'menu_position' => null,

only the middle line is new. There is no real need for it. Just to keep things consistent.

Background
==========
WP automatically adds new capabilities to custom post types registered with the following names:
edit_post
edit_posts
edit_others_posts
publish_posts
read_post
read_private_posts
delete_post

anything placed on the "capability_type" would create custom capabilities.
For example if we use "listing" as our capability type, WP generates capabilities like:
edit_listing
edit_listings
and so on.
Then we only need to add those capabilities to which ever role will be in charge of managing the "listings"

If you wanna get fancy you could go a step further and let the person defining the new post type, define the capabilities name as well (without relying on WP's template).

thx in advance.

#3230

Thanks for the detailed infomation. We'll investigate and add it to Types.

#3247

Thanks for your consideration. I'll bug you again a couple of months down the road if it doesn't make it into the plugin by then :0)

#3293

Just a clarification:
The line
'capability_type' => 'post',

replaces
'capabilities' => false,

I wrote above that this was a new line and that i wasn't that important. In fact, removing the 'capabilities'=>false is required.
I just noticed this while going through the exercise of adding the capabilities again after updating to 0.9.4.1

(no need to respond, really!!)

#8897

Tim

+1 for this addition.

I'd also like to add the ability to assign the custom capability to roles through Types.

I added and changed 2 lines of code to automatically create a new capability using the cpt slug. I had to use Map Cap to assign this new capability to a role, but it would awesome to have it all in one place. This way you could really customize and control access to the post type.

#10406

Big +1

Das Thema „[Geschlossen] Feature Request: Include capability_type on type def“ ist für neue Antworten geschlossen.