In terms of getting things set for the post type arguments, we admittedly don’t have UI built in for that. However, we do have this filter available https://github.com/WebDevStudios/custom-post-type-ui/blob/1.12.1/custom-post-type-ui.php#L538-L550 that would allow you to set them right before registration.
It’s all in the same format as you would see in examples from https://developer.ww.wp.xz.cn/reference/functions/register_post_type/#capability_type and specifically the capabilities/capability type section linked here.
Regarding necessarily how to best go about that, I don’t have a great answer, as I haven’t done a huge amount of roles/capabilities work, so I don’t know best how to address.
@tw2113 Thank you for your fast response.
Can you please tell me how to use this filter. It will be great if you give an example codes for cpt “testimonial”, actually I am not good in WordPress.
Thanks again
Something similar like this would do. Note that I believe the plural version may be based on slug, and not necessarily the label. You’ll want to double check those parts, so don’t take this as for sure would work here. It’s meant as an example of how to add arguments to the register_post_type array we construct.
function cptui_support_filter_post_type( $args, $post_type_slug, $post_type_settings ) {
if ( 'testimonial' !== $post_type_slug ) {
return $args;
}
$args['capabilities'] => array(
'edit_post' => 'edit_testimonial',
'read_post' => 'read_testimonial',
'delete_post' => 'delete_testimonial',
'edit_posts' => 'edit_testimonials',
'edit_others_posts' => 'edit_others_testimonials',
'publish_posts' => 'publish_testimonials',
'read_private_posts' => 'read_private_testimonials',
'create_posts' => 'edit_testimonials',
);
return $args;
}
add_filter( 'cptui_pre_register_post_type', 'cptui_support_filter_post_type', 10, 3 );
Hi @tw2113
$args['capabilities'] => array(
this line of code shows an error of “syntax error, unexpected ‘=>’ (T_DOUBLE_ARROW)”
oops, that should be just an =.
Hi @tw2113
I did as you mentioned but when I trying to edit existing post “You need a higher level of permission. Sorry, you are not allowed to edit posts in this post type.” error occurs and when trying to adding new post “Sorry, you are not allowed to access this page.” error occurs and all testimonial button is also missing.
I may or may not have had the code above to be an exact match for what you need, but it was meant to be an example of how to get the capabilities section into the final arguments for usage with CPTUI, without having to take the entire registration out of CPTUI. You may need to make some tweaks and adjustments for the actual capabilities to match.
Did you ever get this solved @waseemsoa ?
no
this is not solved
“I did as you mentioned but when I trying to edit existing post “You need a higher level of permission. Sorry, you are not allowed to edit posts in this post type.” error occurs and when trying to adding new post “Sorry, you are not allowed to access this page.” error occurs and all testimonial button is also missing.” @tw2113
-
This reply was modified 3 years, 8 months ago by
waseemsoa.
Noted on that part.
As mentioned in my second to last reply, I may not have gotten all of the parts accurate for the values to inject into the arguments needed for the filter, and that part can’t for sure be copy/pasted verbatim, however, this would be the way to get them into the arguments being used to register the post type, without having to do so outside of CPTUI.