Issue with Capability Type
-
Hi,
So I would like to use the Capability Type feature so that I can use another plugin to change user permissions in relation to the custom post type. Unfortunately, when I give it a new ability type name, the whole custom post disappear on the menu.
Is this one of the bugs that you’re planning to fix soon?
Thank you,
Rachel
-
Honestly, I think it may be a hole in the options we make available. If I recall right, if you don’t use one of the default capability types, you need to specify all of the capabilities yourself, which we don’t have at the moment, thus that hole.
I’m using another plugin, user role editor, to specify the capabilities. Yet to get a CPT UI custom post type to show in User Role Editor’s list of posts etc. separate from a normal post, you can need to add in unique name in CPT UI’s Capability Type field.
That works, but for some reason changing The Capability Type from “post” –> “my-name” makes the my custom post type disappear from the main WP menu, making the Capability Type field unusable. I’ll try to get some screen shots to explain better if I’m not being clear.
Screen shots:
https://indiaelder.sites.uofmhosting.net/trouble-shooting-cpt-ui/Thanks!
I’m not personally familiar with the plugin you’re using in conjunction, so I’m not sure exactly what’s going on. If I were to guess, I wager the order of execution may be off, if it’s meant to add custom capability types to post types. Ours may be running and registering afterwards or so. Or it may just not be tying in like it should. The reason why it’s disappearing, is likely because the post capabilities aren’t coming in at the right time, or at all, and thus it’s not even shown because of it.
I deactivated the plugin, but the custom post type still doesn’t show up in the menu when I change the the Custom Post Type’s Capability type, so I think it’s an issue with the CPT UI. The reason I mentioned the other plugin is because the Capability Type field in CPT UI allows me to change the capabilities when using another plugin.
Because WordPress doesn’t know what capabilities to associate with that custom capability type. It is an issue with us by all technical means, because we don’t provide a way to add the custom capabilities for the capability type specified when it’s not one of the core types.
From the codex: “The ‘capability_type’ parameter is used as a base to construct capabilities unless they are explicitly set with the ‘capabilities’ parameter.”
We provide the first one, but not the second one.
I’m not sure how I want to go about it, honestly, because part of me says if one is tinkering with capabilities and capability types, they’re probably fairly advanced with their knowhow of PHP, and why are they using our plugin for this type of thing? As arrogant as that risks sounding.
At the same time, it probably is something to try and take care of, but the topic is not necessarily a simple one either, and a lot of our users may not need to deal with it or even know what the field is related to.
We don’t provide fields for absolutely everything possible with register_post_type and register_taxonomy, but we do provide what we can for the most commonly used/needed fields.
*edited to prefer previous reply*
Ignore possible double posting. I think the .org forums are having issues as I try to reply.
Thanks for your help. I figured out a solution to my issue.
Willing to share your solution in case someone else encounters the same or similar issues?
Hi,
I have exactly the same issue. Could you share the solution please?
Tnx
Honestly, I just hard coded it into the functions.php. I can share the code that worked for me.
But a friend had the same issue (though she may have been using a different, but similar plugin). I believe she said she assigned the custom capability type and the custom post type disappeared from the menu. But when she assigned a user that capability type, it reappeared.
I’d be curious if that actually works.
But if that doesn’t work, here’s the code:
/*Organization Listing Post type */
function register_custom_event_type() {
$labels = array(
‘name’ => (‘Organization Listings’),
‘singular_name’ => (‘Organization Listing’),
‘add_new’ => (‘Add New’),
‘add_new_item’ => (‘Add New Listing’),
‘edit_item’ => (‘Edit Listing’),
‘new_item’ => (‘New Listing’),
‘view_item’ => (‘View Listing’),
‘search_items’ => (‘Search Listing’),
‘not_found’ => (‘No listings found’),
‘not_found_in_trash’ => (‘No listings found in Trash’),
‘parent_item_colon’ => (‘Parent Listing:’),
‘menu_name’ => (‘Organization Listings’),);
$args = array(
‘description’ => ‘organization listings’,
‘labels’ => $labels,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘revisions’ , ‘author’, ‘comments’),
‘hierarchical’ => false,
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘menu_position’ => 3,
‘menu_icon’ => ‘dashicons-store’,
‘show_in_admin_bar’ => true,
‘show_in_nav_menus’ => true,
‘can_export’ => true,
‘has_archive’ => true,
‘exclude_from_search’ => false,
‘publicly_queryable’ => true,
‘capability_type’ => ‘organization-listing’,
‘capabilities’ => array(
‘read_post’ => ‘org_read_post’,
‘publish_posts’ => ‘org_publish_posts’,
‘edit_others_posts’ => ‘org_edit_others_posts’,
‘delete_posts’ => ‘org_delete_posts’,
‘delete_others_posts’ => ‘org_delete_others_posts’,
‘read_private_posts’ => ‘org_read_private_posts’,
‘edit_post’ => ‘org_edit_post’,
‘edit_posts’ => ‘org_edit_posts’,
‘delete_post’ => ‘org_delete_post’,
‘delete_published_posts’ => ‘org_delete_published_posts’,
‘edit_published_posts’ => ‘org_edit_published_posts’,
‘edit_private_posts’ => ‘org_edit_private_posts’,
‘read_private_posts’ => ‘org_read_private_posts’,
),
‘map_meta_cap’ => true
);
register_post_type(‘organization-listing’, $args);}
add_action(‘init’, ‘register_custom_event_type’, 0);
//Add Organization Custom Capabilities to Admin Role
function add_event_caps() {
$role = get_role( ‘administrator’ );$role->add_cap( ‘org_edit_post’ );
$role->add_cap( ‘org_edit_posts’ );
$role->add_cap( ‘org_edit_others_posts’ );
$role->add_cap( ‘org_publish_posts’ );
$role->add_cap( ‘org_read_post’ );
$role->add_cap( ‘read_private_events’ );
$role->add_cap( ‘org_delete_post’ );
$role->add_cap( ‘org_edit_published_posts’ );
$role->add_cap( ‘org_delete_published_posts’ );
$role->add_cap( ‘org_edit_published_posts’ );
$role->add_cap( ‘org_edit_private_posts’ );
$role->add_cap( ‘org_read_private_posts’ );}
add_action( ‘admin_init’, ‘add_event_caps’);//Change title pre-fill text for organization page to “Service Name”
function change_default_title( $title ){
$screen = get_current_screen();if ( $screen->post_type == ‘organization-listing’ ) {
return ‘Service Name’;
}
}add_filter( ‘enter_title_here’, ‘change_default_title’ );
Resolved for me.
User role editor shows custom capabilities separately.
https://s2.postimg.org/jzqjdayzt/Captura_de_Tela_2015_07_21_s_19_43_31.png
tnx
I need to work on the capabilities aspect of CPTUI. I know that much.
Tnx Michael!
- The topic ‘Issue with Capability Type’ is closed to new replies.