我用CPTUI创建了“新闻”自定义帖子类型。并添加具有这些功能的“news_manager”用户角色
edit_post
edit_posts
publish_posts
edit_others_posts
edit_published_posts
然后基本上通过 admin_menu 操作使用 remove_menu_page 阻止对某些页面的访问
remove_menu_page( 'index.php' );
remove_menu_page( 'edit.php?post_type=blog' );
然后使角色重定向到'edit.php?post_type=news'
function loginRedirect( $redirect_to, $request, $user ){
if ( current_user_can( 'news_manager' ) ) {
return "/wp-admin/edit.php?post_type=news";
}
return $redirect_to;
}
add_filter("login_redirect", "loginRedirect", 50, 3);
但是当我创建了一个 news_manager 用户并使用它登录时。URL 重定向是正确的。但是被屏蔽了,wordpress 说这些
您没有足够的权限访问此管理页面。
原因:当前用户具有访问“新闻→所有新闻”菜单项所需的“编辑帖子”功能。
这些仅在 edit.php 页面上被阻止。如果访问特定帖子,则通过。'/wp-admin/post.php?post=22&action=edit'例如
据说用户可以查看但阻止访问。为什么?以及如何解决这些问题。
版本
- WordPress 4.9.4
- 自定义帖子类型 UI 1.5.6