我正在寻找编辑插件在 WordPress 中生成的 CPT(自定义帖子类型),但我不确定如何正确进行。我使用的创建 CPT 的插件是 WPCargo。CPT 的名称是“wpcargo_shipment”。
我编辑这个帖子类型的原因是我需要更精细地控制这个插件的用户权限。我希望限制对后端 WP 的所有其他部分的访问,除了 WPCargo 的 CPT。
我正在尝试使用Memberpress的成员插件来控制我的用户权限。我在这里找到了这篇文章,它讨论了在创建成员插件时调整帖子类型,但不是在事后。
这是我编辑 CPT 的尝试,但我的尝试似乎有些奏效,但并不完全。
/* Edit (wpcargo_shipment) cpt */
function edit_wpcargo_shipment_capability( $args, $post_type ) {
if ( 'wpcargo_shipment' === $post_type ) {
$args['slug'] = $slug; // get and store slug for later use.
$slug_plural = $slug . 's'; // define slug as plural & store for later use.
$args['map_meta_cap'] = true;
$args['capability_type'] = $slug;
$args['capabilities'] = [ // this is the part im most uncertain of.
'create_posts' => 'create_' . $slug_plural,
'delete_others_posts' => 'delete_others_' . $slug_plural,
'delete_posts' => 'delete_' . $slug_plural,
'delete_private_posts' => 'delete_private_' . $slug_plural,
'delete_published_posts' => 'delete_published_' . $slug_plural,
'edit_posts' => 'edit_' . $slug_plural,
'edit_others_posts' => 'edit_others_' . $slug_plural,
'edit_private_posts' => 'edit_private_' . $slug_plural,
'edit_published_posts' => 'edit_published_' . $slug_plural,
'publish_posts' => 'publish_' . $slug_plural,
'read_private_posts' => 'read_private_' . $slug_plural,
'read' => 'read',
];
}
return $args;
}
add_filter( 'register_post_type_args', 'edit_wpcargo_shipment_capability', 10, 2 );
结果:
我没想到会看到并且不理解的东西:
问题:
它已经生成了,如果可以(如果我应该),你是怎么做的?我想知道是否可以在之后编辑 CPT 的参数
笔记:
我曾想过自己从 WPCargo 注销和重新注册 CPT,但想先看看是否有更直接的解决方案。