这对我来说很有效——没有插件。仅允许编辑/添加自定义类型“job”中的帖子的用户:
add_action( \'current_screen\', \'jobs_block_edit\' );
function jobs_block_edit() {
global $current_screen;
$restricted = current_user_can(\'job_user\') && (
($current_screen->base==\'edit\' && $current_screen->id!=\'edit-job\') ||
($current_screen->base==\'post\' && $current_screen->id!=\'job\')
);
if ($restricted) {
exit( wp_redirect( home_url( \'/\' ) ) );
}
}