更改特定角色的默认管理页面
-
16-10-2019 - |
题
我想知道是否有人知道插件或通过编程方式更改特定用户/角色的默认管理页面?
我有一个用于我的插件的主面板页面,当前设置具有自定义角色和插件的权限 成员插件 并希望强迫这些自定义角色的用户将我的主控制面板用于仪表板,因为他们不一定需要访问仪表板。
次要编辑: :除了更改角色的默认仪表板外,还有一种方法可以禁用WordPress仪表板吗?
-zack
解决方案
在您的主题中 functions.php:
function hide_the_dashboard()
{
global $current_user;
// is there a user ?
if ( is_array( $current_user->roles ) ) {
// substitute your role(s):
if ( in_array( 'custom_role', $current_user->roles ) ) {
// hide the dashboard:
remove_menu_page( 'index.php' );
}
}
}
add_action( 'admin_menu', 'hide_the_dashboard' );
function your_login_redirect( $redirect_to, $request, $user )
{
// is there a user ?
if ( is_array( $user->roles ) ) {
// substitute your role(s):
if ( in_array( 'custom_role', $user->roles ) ) {
// pick where to redirect to, in the example: Posts page
return admin_url( 'edit.php' );
} else {
return admin_url();
}
}
}
add_filter( 'login_redirect', 'your_login_redirect', 10, 3 );
其他提示
使用 主题是我的登录 插入。
此插件主题是根据您当前主题的WordPress登录,注册和忘记密码页面。它使用主题中的页面模板创建一个以代替wp-login.php的页面。还包括一个用于侧边栏的小部件。
特征
- ...
- 重定向用户登录并根据其角色注销
- ...
广告仪表板:您可以检查$ _request并根据您的回来,只需使用 wp_redirect();